Today, in debugging my serial scanning program, I originally scanned the device with the database with the database with the database, scan the value of the BScanbreak variable, and the stop button sets the value of the BScanbreak.
bScanBreak = true; bool bScanState = true; while (bScanState) {Sleep (500); bScanState = (bScanThread1 || bScanThread2);} SetCommMask (idComDev, 0); CloseHandle (idComDev); idComDev = NULL; looks code It's no problem, but the two threads stopped scanning but no implementation! (BScanthread1 || BScanthread2) has never been modified, and there is no logical error. Finally, I doubt it to SLEEP, I am suspending a thread for a while, but after multiple tests, SLEP is placed in the main thread, and other threads will also be suspended, but as long as they are not in the main thread, it will not affect other threads.
Finally, I used a Timer to solve the problem!