Task.Factory.StartNew(() =>
{
Thread.CurrentThread.IsBackground = false;
for (int i = 0; i < 1000; i++)
{
Thread.Sleep(1000);
string s = i + " ";
}
});
//①,Application.Current.Shutdown();
//②,Environment.Exit(0);
1、当 Thread.CurrentThread.IsBackground = false; 时 ①只关掉了UI而后台进程没有关掉;
2、当 Thread.CurrentThread.IsBackground = true; 时 ①②都可以关掉UI和进程。
3、Process.GetCurrentProcess().Kill(); 彻底结束进程