S
supermonkey
In my opinion, all subthreads will be terminated when the main thread exit
,but the following program pose a surprise to me~
After "Hello world!" was displayed on the screen, the program will wait
until the "RunMe called" was displayed!
why? is the subthread active though the main thread has exited?
how to explain this problem? Thank you
// thread.cs
using System;
using System.Threading;
namespace ConsoleApplication10
{
class ThreadTest
{
public void RunMe()
{
Thread.Sleep(1000);
Console.WriteLine("RunMe called");
}
static void Main()
{
ThreadTest b = new ThreadTest();
//Thread t = new Thread(b.RunMe);
Thread t = new Thread(new ThreadStart(b.RunMe));
t.Start();
Console.WriteLine("Hello world!");
}
}
}
,but the following program pose a surprise to me~
After "Hello world!" was displayed on the screen, the program will wait
until the "RunMe called" was displayed!
why? is the subthread active though the main thread has exited?
how to explain this problem? Thank you
// thread.cs
using System;
using System.Threading;
namespace ConsoleApplication10
{
class ThreadTest
{
public void RunMe()
{
Thread.Sleep(1000);
Console.WriteLine("RunMe called");
}
static void Main()
{
ThreadTest b = new ThreadTest();
//Thread t = new Thread(b.RunMe);
Thread t = new Thread(new ThreadStart(b.RunMe));
t.Start();
Console.WriteLine("Hello world!");
}
}
}