Saturday, July 23, 2005

No Thread.Abort() in .NET CF 1.0

You cannot call Thread.Abort() in .NET CF 1.0, so how do you close/stop a thread?

See this HOWTO on msdn for a workaround.

1 comment:

Anonymous said...

I came across this too.

The workaround you link to is too complicated, and, much more importantly, not thread safe!

I worked around this by setting a bool that indicates whether threads in infinite loops should exit. Then, when an exit is requested, I set the bool, call System.Windows.Forms.Form.Close() and then Application.Exit(). The form closes immediately, but the application won't exit until all the threads die. But that's only a problem if the user tries to restart the application before the other threads actually exit...