Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading;
Comprehensive demonstration of namespace thread pool judgment end
{
Class Program
{
public static int iCount = 0;
public static int MaxCount = 10;//allows a thread pool to run up to 10 threads
static ManualResetEvent Eventx = new ManualResetEvent (false); Creates a new ManualResetEvent object and initializes it to a signal-free State
static void Main (string[] args)
{
Console.WriteLine ("ManualResetEvent is initially no signal State");
Console.WriteLine ("The thread pool has a maximum value of {0} threads.") ", MaxCount);
for (int iItem = 1; iItem <= MaxCount; iitem++)
{
Inserting a queue element
Console.WriteLine ("Join thread {0}", IItem);
ThreadPool.QueueUserWorkItem (New WaitCallback (FUN1), (object) iItem);
}
Console.WriteLine ("Wait for the thread pool to complete ... "); Waits for the event to complete, that is, the thread calls the Manualresetevent.set () method
Eventx.waitone (Timeout.infinite, true); The WaitOne () method causes the thread that calls it to wait until the Eventx.set () method is called
Console.WriteLine ("Thread pool end!") ");
Console.ReadLine ();
}
public static void Fun1 (Object j)
{
Console.WriteLine ("{0} {1}:", Thread.CurrentThread.GetHashCode (), j.tostring ());
Thread.Sleep (1000);
Interlocked.Increment (ref ICount);
if (ICount = = MaxCount)
{
Console.WriteLine ();
Console.WriteLine ("Set ManualResetEvent to have signal status, Setting eventx");
Eventx.set ();
}
}
}
}
Go Whether C # multithreading ends can be judged by the thread pool