killing thread in C#

  • Thread starter Thread starter wanderer
  • Start date Start date
W

wanderer

If I want to kill a thread prematurely (before it
completes it's passed in function), what's the best way
to do that in CF?

Also, how do I pass in arguments to the Thread's
function? Or do I have to use globals? Thanks.
 
wanderer,

The best way to kill a thread is to have it check some variable in a loop and
see if it should kill itself. That way the thread has an opportunity to shut
down cleanly and release any resources before exiting. I usually use member
variables or properties for setting up data that the thread can access (and that
might be used to signal the thread to stop) since my thread procs are usually
just methods of classes that are also responsible for creating, starting and
stopping the worker threads.
 
Back
Top