Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

What happens to this thread?

$
0
0
Hello,

I am creating a console application..

here is brief code snippet..

// static void Main(....

AutoResetEvent are = new ..

System.Threading.Timer timer = new System.Threading.Timer(

           new TimerCallback(delegate(Object state) {

               ...some logic..

               if(..somelogic) {

                        ....

                        are.Set();

               }

               else {

                       Console.ReadLine();

               }

           }, are, 0, 1000);

are.WaitOne();

..//Disposal

..//End Main

Basically, TimerCallback is being called every second...if some my logic is met, that is going to signal then the timer will be disposed and the program exits...

According to MSDN doc, this timer callback executes in a separate thread pool thread that is provided by the system.

Well..let's suppose that two different threads  in the pool executes this during 2 second...so

Thread ID 1 : my logic is false,.so it runs Console.ReadLine()..then ..this will block the thread for user input.

Thread ID 2 : let's suppose that this point, my logic is true..so set the signal....then my console application exits...

Then what happens to my Thread ID 1?...is this something like zombie thread hanging around somewhere in the pool to hold up the system resource?..

OR as soon as my program exits, this Thread1 automatically releases and returns to the thread pool to serve next task?

Thanks in advance.

Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>