microkarl Posted July 13, 2005 Posted July 13, 2005 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 Quote Donald DUCK : YOU ARE FIRED!!!
Wile Posted July 13, 2005 Posted July 13, 2005 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). Quote Nothing is as illusive as 'the last bug'.
Diesel Posted July 13, 2005 Posted July 13, 2005 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.