c# - How to know that I have another thread running apart from the main thread? -


Suppose I have such a regular one:

  Private Zero Button 1_Click ( Object Sender, EventArgs e) {Thread T = New Thread (New Thread Start (some_work)); T.Start (); }  

I need to put a condition that, "If the thread is not running separately from the main thread, start a new thread".

But how to test for a thread running other than the main thread?

The easiest solution is to either store a reference for the current thread, or just a Set flags in which you have a thread running

You should also keep that field (context or flag) so that the thread exits, then it should be set in that area so that the next "Start Request" is a new start.

Easiest way:

  Private volatile threads _Thread; ... if (_Thread == faucet) {_Thread = new thread (new threadstart (some_work)); _Thread.Start (); } Private Zero Some_Work () {try {// Your Thread Code Here} Finally {_Thread = null; }}  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -