Wednesday, January 11, 2017

Difference between background thread and foreground thread

Foreground Thread


Foreground threads are threads which will continue to run until the last foreground thread is terminated. In another way, the application is closed when all the foreground threads are stopped.

So the application won't wait until the background threads are completed, but it will wait until all the foreground threads are terminated.

By default, the threads are foreground threads. So when we create a thread the default value of IsBackground property would be false.

Background Thread


Background threads are threads which will get terminated when all foreground threads are closed. The application won't wait for them to be completed.

We can create a background thread like following:
  1. Thread backgroundThread = new Thread(threadStart);  
  2. backgroundThread.IsBackground = true;  
  3. backgroundThread.Start();  

No comments:

Followers

Link