What happen to a thread when the calling application shuts down?

Viewed 40

Suppose that i have a service which create a thread like the following:

        Thread t = new Thread(new ThreadStart(delegate
        {
            MyOtherClass.DoSomething();
        }
        ));

        t.IsBackground = true;
        t.SetApartmentState(ApartmentState.STA);
        t.Start();

What happen to my thread if for any reason, the service shuts down (aside from physically shutting down the pc of course)

1 Answers

By default a Threadis a foreground thread. A process stays running until all its foreground threads have finished.

If a thread is a background thread then it won't stop the application from shutting down. They'll be killed when the process exits.

You can make a thread a background thread by setting the IsBackground property to true.

Related