Background threads

We can also declare a thread as background thread by specifying IsBackground property to true

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace ThreadPrograms

    class Program
        static void Main(string[] args)
            var t1 = new Thread(ThreadMain) { Name = "MyNewThread", IsBackground = true};
            Console.WriteLine("Main thread ending now.");

        static void ThreadMain()
            Console.WriteLine("Thread {0} started", Thread.CurrentThread.Name);
            Console.WriteLine("Thread {0} completed", Thread.CurrentThread.Name);




Add a Comment

Your email address will not be published. Required fields are marked *