Home » Community » Newbie corner » Shutdown procedure by clicking red x
Re: Shutdown procedure by clicking red x [message #30120 is a reply to message #30002] |
Thu, 09 December 2010 21:37   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
After searching found this that gets deep into the red X to close:
http://www.codeguru.com/columns/vb/article.php/c15579
Also a thread wait would not work as the threads will continuously run unless shut down, which was the problem that seldom happened that required taskmanager or the MS pop up to terminate the app.
With some semi intuitive reasoning to end the threads that have in a while loop with Sleep(980) added this:
// A global bool end;
while (CommPort.ReadDataWaiting() ) {
if(end) break;
...
Sleep(980);
....
void Exit0() {
end = true; Sleep(2000);
if(CommPort.IsOpened()) CommPort.Close();
if(CommPort2.IsOpened()) CommPort2.Close();
Thread::ShutdownThreads();
Break(); // Closes window with 'Cancel'
}
void endX(){end = true; Sleep(2000);}
GUI_APP_MAIN{
GPSv2().Run();
endX();
if(CommPort.IsOpened()) CommPort.Close();
if(CommPort2.IsOpened()) CommPort2.Close();
Thread::ShutdownThreads();
}
Setting end = true; and the Sleep(2000); gives the while loop time to break.
Sometimes if a GPS receiver is not closed properly pulling the receiver plug is about the only way.
This works when clicking the red x (or at least I have not had the error again) as well as the explicit Exit.
Neil
http://www.nlneilson.com/gpsv2.html
[Updated on: Fri, 10 December 2010 00:32] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Mon Apr 28 20:53:19 CEST 2025
Total time taken to generate the page: 0.00680 seconds
|