When does a multithreaded console application exit?

前端 未结 2 2026
醉梦人生
醉梦人生 2020-12-11 17:58
class Program
{
    public static void Main(String[] args)
    {
        var c = new C();
        var thread = new Thread(new ThreadStart(c.F));
        thread.Start         


        
2条回答
  •  情歌与酒
    2020-12-11 18:31

    A process ends when all foreground threads terminate

    From Thread.IsBackground remarks on foreground threads vs background threads:

    A thread is either a background thread or a foreground thread. Background threads are identical to foreground threads, except that background threads do not prevent a process from terminating. Once all foreground threads belonging to a process have terminated, the common language runtime ends the process. Any remaining background threads are stopped and do not complete.

提交回复
热议问题