Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, I have a question on multithreading, is there a way for the main thread to know how many, if any, worker thread(s) is still running in the background.

 

Carl

Donald DUCK : YOU ARE FIRED!!!
Posted
Depends on whether you can still access that specific thread. If you have the Thread object that represents the thread, you can use the IsAlive property to see if it is still alive (and thus running).
Nothing is as illusive as 'the last bug'.
Posted

More concretely, create an ArrayList or Array to keep track of the threads and check the IsAlive Property

 

ArrayList workerThreads = new ArrayList();

 

//create threads

System.Threading.Thread th = new System.Threading.Thread(new ThreadStart(someFunc);

 

workerThreads.Add(th);

 

foreach (object obj in workerThreads)

{

System.Threading.Thread tempThread = (System.Threading.Thread)obj;

Console.WriteLine(tempThread.IsAlive.ToString());

}

 

//something as such

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...