Arduino MEGA2560 suddenly disconnectes from pc but visible in device manager

USB serial port was working fine between c# and ardiuno but suddenly after random time serial port disconnects but device is still visible and working fine in COM Port
Ardiuno is working fine on its own. But i couldn’t communicate to ardiuno from pc.
i tried to disable devices driver and reenable it and it worked fine i really need help here fellas

c# code.txt (7.11 KB)

arduino code.txt (26.8 KB)

Turn off setting to let Windows power down USB ports.