By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,738 Members | 1,682 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,738 IT Pros & Developers. It's quick & easy.

how to restart a thread

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"Kranthis" <an*******@discussions.microsoft.com> wrote in message
news:11*****************************@phx.gbl...
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

Nov 15 '05 #2

P: n/a
When value reaches 100 you can spawn new thread from the current with the
same thread function

"Kranthis" <an*******@discussions.microsoft.com> wrote in message
news:11*****************************@phx.gbl...
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

Nov 15 '05 #3

P: n/a
Don't use threads for this, use asynch. delegates or workerthreads from the
threadpool. Check the MSDN doc's for samples.
Willy.

"Kranthis" <an*******@discussions.microsoft.com> wrote in message
news:11*****************************@phx.gbl...
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

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.