Random BSOD while app is running

I am making a windows application using Dart which uses a certain USB UART to be able to be able to use the funcationalities. I have faced system crash i.e. BSOD randomly while my application is runnning. This happened when the UART device was turned off and then turned on. I haven’t been able to figure out the reason behind the crash. My initial hunch was that since I was scanning for UART every 2 seconds it could have happened, but not I don’t search for it unless a button is pressed to scan for it.

I am using SerialPort class’s SerialPort.availablePorts to scan for COM Ports.

High probability that your COM driver is throwing an exception. The fact that the device turns on/off indicates that (and the BSOD, where the majority of times is in faulty device drivers). Guess you’re doing something the driver doesn’t like. The BSOD dump will have more info (you’ll need someone that can help you with windows debug).