简体   繁体   English

线程可以在App终止后存活吗

[英]Can Thread survive App termination?

If a .NET program creates and starts a System.Threading.ThreadPool thread, and then the program ends (either naturally or by crashing): 如果.NET程序创建并启动System.Threading.ThreadPool线程,然后程序结束(自然地或通过崩溃):

  • Is it possible for the Thread to survive and carry on processing on its own? Thread可以存活并自行进行处理吗?
  • Is it possible that an App will look like it has terminated due to the main UI thread having ended, but for a background thread to carry on running invisibly? 由于主UI线程已经结束,应用程序是否可能看起来已经终止,但后台线程是否可以无形地继续运行?

根据定义,如果进程的其中一个线程仍在工作,那么它实际上并没有结束

一个线程不能独立于一个进程生存,所以没有。

No. And from the horse's mouth (MSDN) 不,从马的嘴里(MSDN)

The threads in the managed thread pool are background threads. 托管线程池中的线程是后台线程。 That is, their IsBackground properties are true. 也就是说,它们的IsBackground属性是真的。 This means that a ThreadPool thread will not keep an application running after all foreground threads have exited. 这意味着在所有前台线程退出后, ThreadPool线程不会保持应用程序运行。

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

相关问题 FormsAuthenticationTicket可以在应用程序池回收中存活吗? - Can a FormsAuthenticationTicket survive an app pool recycle? 如何防止因应用程序终止而导致线程中止? - How to prevent aborting of thread due to app termination? C# 线程终止和 Thread.Abort() - C# Thread Termination and Thread.Abort() .NET 控制台应用程序 - 它能否检测到自己因系统关闭而即将终止? - .NET Console App - can it detect its own imminent termination due to system shutdown? 如何使控制器对象在会话之间保留下来? - How can I make the controller object survive between sessions? MSMQ - 队列进程重启/服务器重启后队列是否存在 - MSMQ - can a queue survive a queue process restart/server restart WCF通道随机变为故障(在线程终止时) - WCF channel randomly becomes Faulted (upon thread termination) 在 STA 线程中创建的 COM RWC 在线程终止时与底层 COM 对象断开连接是否正常? - Is it normal for COM RWC's created in STA thread to disconnect from the underlying COM object on thread termination? 可以列表 <T> 并且它的项目在一个表格的生命周期中创建并返回到另一个类,在它被破坏后存活下来? - Can a List<T> and its items created and returned to another class during the lifetime of a form survive after its destruction? 我可以从C#向远程应用程序域中注入线程吗 - Can I inject a thread in a remote app domain from C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM