C# 如何中止线程

C# 如何中止线程,c#,.net,multithreading,C#,.net,Multithreading,我使用这样的代码 List<Thread> list = new List<Thread>(); Thread newThread = new Thread(delegate() { stream(string); }); this.list.Add(newThread); newThread.Start(); private void Form1_FormClosing(object sender, F

我使用这样的代码

List<Thread> list = new List<Thread>();

Thread newThread = new Thread(delegate() { stream(string); });
                this.list.Add(newThread);
                newThread.Start();

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            foreach (var item in list)
            {
                item.Abort();
            }
        }
List List=新列表();
线程newThread=新线程(委托(){stream(string);});
this.list.Add(newThread);
newThread.Start();
私有作废Form1\u FormClosing(对象发送方,FormClosingEventArgs e)
{
foreach(列表中的变量项)
{
item.Abort();
}
}
但在关闭任务管理器中的进程后,如何退出整个应用程序

我在谷歌上搜索了很多次,但所有的例子对我来说都很难理解

退出应用程序:

 Application.Exit(); 
退出应用程序:

 Application.Exit(); 

使用调试器。如有必要,使用工具将其连接并连接到流程。Debug+breakall,Debug+Windows+线程显示哪些线程仍在运行。使用Thread.IsBackground属性保留代码。

使用调试器。如有必要,使用工具将其连接并连接到流程。Debug+breakall,Debug+Windows+线程显示哪些线程仍在运行。使用Thread.IsBackground属性保留代码。

如果以后台线程的形式运行线程,则退出主应用程序时线程将停止 像这样:

Thread newThread = new Thread(delegate() { stream(string); });
this.list.Add(newThread);
newThread.isBackground = true;
newThread.Start();

如果您将线程作为后台线程运行,那么当您退出主应用程序时,线程将停止 像这样:

Thread newThread = new Thread(delegate() { stream(string); });
this.list.Add(newThread);
newThread.isBackground = true;
newThread.Start();

您的意思是调用Application.Exit();在event FormClosing中?这只会终止UI线程,并不能解决此问题。您的意思是调用Application.Exit();在event FormClosing?中,这只会终止UI线程,并不能解决此问题。