Rapid creation and Abortion of threads

  • Thread starter Thread starter Jagadish
  • Start date Start date
J

Jagadish

Hi,
My application requires to create a few threads on the
occurance of an event E1 and the same threads need to be
aborted on the occurance of another event E2. Iam not
using .Net thread pool threads. Iam using system threads
by using Thread objects and delegates. Threads are aborted
by making an explicit call to Thread.Abort().

Occurance of events E1 and E2 are not under the control of
my application. My application runs stable for a few hours
but once E1 and E2 start repeatedly occuring at a very
fast rate, new threads are also started and aborted at a
very fast rate. As a result, some threads are not aborted.
Apparently, there is a thread leak, memory leak in my
application.

So, how do i ensure that the threads are aborted and are
removed from memory?

Thanks in advance.
Jagadish
 
Jagadish, are you sure that threads aren't being aborted? Have you tried
putting some logging in to ensure that that is in fact what is going on?
You can also watch the thread count for your app using Task Manager.

My guess is that your threads are being aborted and cleaned up but that it
isn't happening when you would expect when E1 and E2 happen quickly. If
that's not the case could you include some code demonstrating what you are
seeing?
 
Abort does not guarantee a thread to abort. Look into the Win32 API
TerminateThread. (along with a number of others that you need to use to get
a real HANDLE, duplicate it, and then finally close it out.)
 
Back
Top