how to restart a thread

  • Thread starter Thread starter Kranthis
  • Start date Start date
K

Kranthis

Hi,
I want to restart a thread after same variable value in
the thread reaches 100 in c# . How can I do. Please
suggest me any solution
 
Hi Kranthis:

What I would do is have the thread that is counting be a child thread. When
it is completed processing the 100 things it does, have it die (exit the
thread).
In your parent thread, monitor your child thread's status. (Thread.IsAlive
method) If it is non running, you know it finished. At that point, you would
restart it (Thread.Start())
The tricky part will be the monitoring in the parent thread. This you will
need to do without cause the parent thread to stop responding (like looping
forever until child thread is dead). My suggestion would be to read up on
Callbacks, where the child can post a callback to the parent telling it that
it has completed. Parent can then start new thread. Some other suggestions:
using a ThreadPool, or using a Mutex/WaitFor combination in parent thread.

Hope this helps, I know not very detailed, to early in the AM to think:-)

S
 
When value reaches 100 you can spawn new thread from the current with the
same thread function
 
Don't use threads for this, use asynch. delegates or workerthreads from the
threadpool. Check the MSDN doc's for samples.
Willy.
 
Back
Top