例如 主程序调用了两个线程a和b
我想让主程序等到a,b都执行完毕后再  往下运行
应该怎么做?
最好能有示例代码?

解决方案 »

  1.   

    你在主线程中加上public static void Main()
    {
         a.Join();
         b.Join();     a.Start();
         b.Start();     //下面加上你的代码
    }
    试试
      

  2.   

    Thread.Join().using System;
    using System.Threading;class IsThreadPool
    {
        static void Main()
        {
            AutoResetEvent autoEvent = new AutoResetEvent(false);        Thread regularThread = 
                new Thread(new ThreadStart(ThreadMethod));
            regularThread.Start();
            ThreadPool.QueueUserWorkItem(new WaitCallback(WorkMethod), 
                autoEvent);        // Wait for foreground thread to end.
            regularThread.Join();        // Wait for background thread to end.
            autoEvent.WaitOne();
        }    static void ThreadMethod()
        {
            Console.WriteLine("ThreadOne, executing ThreadMethod, " +
                "is {0}from the thread pool.", 
                Thread.CurrentThread.IsThreadPoolThread ? "" : "not ");
        }    static void WorkMethod(object stateInfo)
        {
            Console.WriteLine("ThreadTwo, executing WorkMethod, " +
                "is {0}from the thread pool.", 
                Thread.CurrentThread.IsThreadPoolThread ? "" : "not ");        // Signal that this thread is finished.
            ((AutoResetEvent)stateInfo).Set();
        }
    }参见:
    Thread.Join Method 
    ms-help://MS.MSDNQTR.v90.en/fxref_mscorlib/html/56ed7b6f-efe0-67e7-34bc-766dd9f693f9.htm
      

  3.   

    ms-help://MS.MSDNQTR.v90.en/fxref_mscorlib/html/56ed7b6f-efe0-67e7-34bc-766dd9f693f9.htm有在线的帮助吗?
      

  4.   

    如果我是往线程池里加入了很多WaitCallBack  如何使线程池中的线程都执行完毕前阻塞主线程呢?