Aborting threads

  • Thread starter Thread starter Mantorok
  • Start date Start date
M

Mantorok

Hi all

I have an app that can kick off one or more threads, a thread will run a
COM EXE Server.

What I want to do is provide the facility to cancel a thread that is running,
and also, when the app closes down to close all running threads.

What's the best way to achieve this without running into problems?

Thanks
Kev
 
To make threads end when the application exits you can make them
background threads ( by setting the 'IsBackground' property to true).

You can end treads by calling the Thread.Abort() functions. Make sure
you read the docs on how to properly handle the ThreadAbortException
which may occur at any point in the code the thread is running.

You can also have your threads check some sort of flag at a regular
interval to determine if they should continue or end.

I'm not sure how you should hanvle the COM thread.
 
Hello Mantorok,

Read there http://www.dotnetconsult.co.uk/weblog/PermaLink.aspx/4f52c396-1b0d-4419-8871-6ca6992460ca

M> I have an app that can kick off one or more threads, a thread will
M> run a COM EXE Server.
M>
M> What I want to do is provide the facility to cancel a thread that is
M> running, and also, when the app closes down to close all running
M> threads.
M>
M> What's the best way to achieve this without running into problems?
M>
M> Thanks
M> Kev
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Back
Top