Mega Code Archive

 
Categories / C# Tutorial / Thread
 

Set IsBackground to true

using System; using System.Collections.Generic; using System.Text; using System.Threading; public class Printer {     public void PrintNumbers() {         Console.WriteLine("-> {0} is executing PrintNumbers()", Thread.CurrentThread.Name);         Console.Write("Your numbers: ");         for (int i = 0; i < 10; i++) {             Console.Write(i + ", ");             Thread.Sleep(2000);         }         Console.WriteLine();     } } class Program {     static void Main(string[] args) {         Printer p = new Printer();         Thread bgroundThread = new Thread(new ThreadStart(p.PrintNumbers));         bgroundThread.IsBackground = true;         bgroundThread.Start();     } }