Message Pump/Thread quiting trouble

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Chris,

Help me out wih this? I got a message pump similar to the one in ApplicationEx.cs as you suggested working great. However, I started to get a bit clever and added a thread to do some work (is based on a timer). And when running with a thread and calling Exit (in other words PostQuitMessage ) from this new thread the message pump never receives the quit message
Calling the same method with out a thread works with out a problem
I am guessing that my thread is causing the message pump to assume that that message is not for it?
Can't you terminate an app from a thread. I was looking to see if it was a problem were I had to call Invoke. But I am not using any GUI components at all, so I don't see any Invokes I can call
Do you have any suggestions?

I really need to run the code with a Timer

Thank
 
I found a work around the problem. Instead of using a Timer object I am creating a loop with a Thread.Sleep( timeOut ) in it works fine. But I am still very curious as to how you would resolve the problem if you wanted to call Exit from with in a Thread

Thanks
 
The best way for a thread to exit is to just return. Usually apps use a
globally visible variable that all the threads can see that indicates when
they should stop. Worker threads run in a loop checking this value,
returning when it's true.
--
Ginny Caughey
..Net Compact Framework MVP

fhunter said:
I found a work around the problem. Instead of using a Timer object I am
creating a loop with a Thread.Sleep( timeOut ) in it works fine. But I am
still very curious as to how you would resolve the problem if you wanted to
call Exit from with in a Thread.
 
Back
Top