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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Thread naming and killing by name 2
Threads 12
urgent: Thread Termination. 2
newby on threads 2
Threading and Serial port issue 4
force kill thread 6
Threading Abort problem 1
Killing a blocking thread ? 15

Back
Top