If t.ThreadState = ThreadState.Stopped Then
    '完成
EndIf

解决方案 »

  1.   

    that's not a bad question!
      

  2.   

    myThread mThread = new myThread();
                try
                {
                    Console.Title = "博客搬家后台服务 --Sean Pu 2007.08.23)";
                    Parse.Cl("博客搬家后台服务开始运行...", ConsoleColor.DarkGreen);
                    mThread.MainThread();  //Start MainThread and MainThread start some child threads              
                    XXX
                    mThread.TerminateThread();//terminate child threads
                    Parse.Cl("现在开始停止所有服务,请稍等片刻....");
                    while (myThread.ThreadNum != 0)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    Console.Beep();
                    Parse.Cl("博客搬家后台服务停止完成.");
                    Parse.Cl("Press any key to continue... ...");
                    Console.ReadKey();
                }
      

  3.   

    我是在类中设一个Dictionary然后在线程函数中写状态进Dictionary在主函数中读都是某状态就OK 了
      

  4.   

    采用WaitHandle等待所有线程执行完毕!using System;
    using System.Threading;public sealed class App 
    {
        // Define an array with two AutoResetEvent WaitHandles.
        static WaitHandle[] waitHandles = new WaitHandle[] 
        {
            new AutoResetEvent(false),
            new AutoResetEvent(false)
        };    // Define a random number generator for testing.
        static Random r = new Random();    static void Main() 
        {
            
            DateTime dt = DateTime.Now;
            Console.WriteLine("Main thread is waiting for BOTH tasks to complete.");
            ThreadPool.QueueUserWorkItem(new WaitCallback(DoTask), waitHandles[0]);
            ThreadPool.QueueUserWorkItem(new WaitCallback(DoTask), waitHandles[1]);
            WaitHandle.WaitAll(waitHandles);
            
            Console.WriteLine("Both tasks are completed (time waited={0})", 
                (DateTime.Now - dt).TotalMilliseconds);        // Queue up two tasks on two different threads; 
            // wait until any tasks are completed.
            dt = DateTime.Now;
            Console.WriteLine();
            Console.WriteLine("The main thread is waiting for either task to complete.");
            ThreadPool.QueueUserWorkItem(new WaitCallback(DoTask), waitHandles[0]);
            ThreadPool.QueueUserWorkItem(new WaitCallback(DoTask), waitHandles[1]);
            int index = WaitHandle.WaitAny(waitHandles);
            // The time shown below should match the shortest task.
            Console.WriteLine("Task {0} finished first (time waited={1}).",
                index + 1, (DateTime.Now - dt).TotalMilliseconds);
        }    static void DoTask(Object state) 
        {
            AutoResetEvent are = (AutoResetEvent) state;
            int time = 1000 * r.Next(2, 10);
            Console.WriteLine("Performing a task for {0} milliseconds.", time);
            Thread.Sleep(time);
            are.Set();
        }
    }
      

  5.   

              CheckIp *checkrun[10];
              for (int j=0;j<10 && !q1->Eof;j++)
              {
                   MainForm->Memo2->Lines->Add(DateTimeToStr(Date()+Time())+" 检测 "+q1->FieldByName("ip")->AsString);
                   //MainForm->Label3->Caption=IntToStr(MainForm->Label3->Caption.ToInt()+1);
                   checkrun[j]=new CheckIp(false);
                   checkrun[j]->FreeOnTerminate=false;
                   checkrun[j]->ip=q1->FieldByName("ip")->AsString;
                   checkrun[j]->port=q1->FieldByName("port")->AsString.ToInt();
                   checkrun[j]->Resume();
                   q1->MoveBy(1);
              }
              for (;checkrun[0]->islive || checkrun[1]->islive || checkrun[2]->islive || checkrun[3]->islive || checkrun[4]->islive || checkrun[5]->islive || checkrun[6]->islive || checkrun[7]->islive || checkrun[8]->islive || checkrun[9]->islive;)
                   Sleep(1000);
              delete  checkrun;
    __fastcall CheckIp::CheckIp(bool CreateSuspended)
            : TThread(CreateSuspended)
    {
            islive=true;
    }
    //---------------------------------------------------------------------------
    void __fastcall CheckIp::Execute()
    {
            //---- Place thread code here ----
            //我的程序代码.....
            islive=false;
            return;
    }