RT

解决方案 »

  1.   

    Thread.Join 方法阻塞调用线程,直到某个线程终止时为止。
    [C#] 
    using System;
    using System.Threading;class Test
    {
        static TimeSpan waitTime = new TimeSpan(0, 0, 1);    public static void Main() 
        {
            Thread newThread = 
                new Thread(new ThreadStart(Work));
            newThread.Start();        if(newThread.Join(waitTime + waitTime))
            {
                Console.WriteLine("New thread terminated.");
            }
            else
            {
                Console.WriteLine("Join timed out.");
            }
        }    static void Work()
        {
            Thread.Sleep(waitTime);
        }
    }
      

  2.   

    你可以使用线程池去实现你的要求,线程池中提供的ThreadPool.QueueUserWorkItem和ManualResetEvent完全可以满足你的要求。在微软的例子中叶提供了相关的列子。地址为:http://msdn.microsoft.com/en-us/library/3dasc8as(VS.80).aspx