我知道这不是您遇到的问题,但是可能发生这种情况的另一个原因是您在应用程序中打开了一个非后台线程。
using System;
using System.Threading;
using System.Windows.Forms;
namespace Sandbox_Form
{
static class Program
{
private static Thread thread;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
thread = new Thread(BusyWorkThread);
thread.IsBackground = false;
thread.Start();
Application.Run(new Form());
}
public static void BusyWorkThread()
{
while (true)
{
Thread.Sleep(1000);
}
}
}
}
什么时候IsBackground
它false
会保持你的程序打开直到线程完成,如果你设置IsBackground
线程true
将不会保持程序打开。像BackgroundWoker
,ThreadPool
和Task
所有内部使用IsBackground
设置为的线程true
。