Aborting threads

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
 
N

Natrajk

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.
 
M

Michael Nemtsev

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
 

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

Top