Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何中止线程Tcp连接_C#_Multithreading - Fatal编程技术网

C# 如何中止线程Tcp连接

C# 如何中止线程Tcp连接,c#,multithreading,C#,Multithreading,我开始了解我成功使用的线程,但我不能中止线程 程序无法成功结束 请帮助我如何中止 for (int i = 0; i < dtProd.Rows.Count; i++) { sayacno = dtProd.Rows[i].ItemArray[2].ToString(); komut = "<25></25>"; Connection TCP =

我开始了解我成功使用的线程,但我不能中止线程 程序无法成功结束

请帮助我如何中止

for (int i = 0; i < dtProd.Rows.Count; i++)
            {
                sayacno = dtProd.Rows[i].ItemArray[2].ToString();
                komut = "<25></25>";
                Connection TCP = new Connection("as","sd","fd","gd");
                Thread t = new Thread(new ThreadStart(TCP.Bagla));
                t.IsBackground = true;
                t.Start();
                threads.Add(t);
                Thread.Sleep(100);
            }

            for (int t = 0; t < threads.Count; t++)
            {
                try
                {
                    threads[t].Join();
                    threads[t].Abort();
                }
                catch (ThreadAbortException tx)
                {
                    Console.Write(tx.ToString());
                }            
            }
for(int i=0;i
我想您已经更改了以下呼叫:

   threads[t].Join();
   threads[t].Abort();
致:

threads[t].Join()
将导致调用线程阻塞,直到
线程[t]
线程结束。我不希望它能到达中止线。
   threads[t].Abort();
   threads[t].Join();