繁体   English   中英

如何中止线程Tcp连接

[英]How to Abort Thread Tcp Connection

我开始学习成功使用的线程,但是我无法中止线程程序无法成功结束。

请帮助我如何中止?

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());
                }            
            }

我认为您有以下来自以下方面的更改:

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

至:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM