调用abort()强行终止把,不知行不行。不过的你得把你那10个线程引用保存一下了。

解决方案 »

  1.   

    InterMa(因特马)说的对,楼主这样的线程没有标识,不好中止。
    可以试试把他们放在线程池里,来做中止
      

  2.   

    Tomgus(小桥流水) 
    能说一下怎么样把我的程序改成线程池呢?
    谢谢
      

  3.   

    线程池中的线程还是的通过对象引用来终止把,如果你的线程中的代码类似while(true)的死循环结构,放到线程池中不但不会终止,还会可能诸塞其他线程进入(如果线程池中已满,你那可是10个线程阿),影响性能。
    这是我的理解。
      

  4.   

    设置一个关闭得信号量//声明
    private IntPtr closeEvent;
    private string closeEventName = "CloseEvent";//类初始化中
    closeEvent = Win32API.CreateEvent(IntPtr.Zero, Convert.ToInt32(true), Convert.ToInt32(false), closeEventName);//线程中
    int res = Win32API.WaitForSingleObject(closeEvent, 10);
    if ( res == (int)SyncAPIConstants.WAIT_OBJECT_0 )
    {
        // Exit the thread.
        return;
    }//关闭
    Win32API.SetEvent(closeEvent);
      

  5.   

    忘记了,补充一点:
       start线程时  
       Win32API.ResetEvent(closeEvent);//树起关闭
      

  6.   

    TO:enzhiyiqiu(蜀道消程)
    Win32API是?
    多谢
      

  7.   

    [DllImport("kernel32.dll", EntryPoint="CreateEvent", SetLastError = true)]
            public static extern IntPtr CreateEvent(
                IntPtr lpEventAttributes, 
                int bManualReset, 
                int bInitialState, 
                string lpName
                );         [DllImport("kernel32.dll", EntryPoint="SetEvent", SetLastError = true)]
            public static extern int SetEvent(IntPtr hEvent);         [DllImport("kernel32.dll", EntryPoint="ResetEvent", SetLastError = true)]
            public static extern int ResetEvent(IntPtr hEvent);         [DllImport("kernel32.dll", EntryPoint="WaitForSingleObject", SetLastError = true)]
            internal static extern int WaitForSingleObject(
                IntPtr hHandle, 
                uint dwMilliseconds
                );
      

  8.   

    定义在整个文件里Thread[] testThread=new Thread[10];然后for (int i=0; i<10; i++)
    {
       testThread[i] = new Thread(new ThreadStart(aaa));
       testThread[i].Start();
    }//结束
    for (int i=0; i<10; i++)
    {
       testThread[i].Abort()
    }