• Top Posts

    using baground thread in c#

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

    namespace ConsoleApplication7
    {
        class Program
        {
            public static void Main()
            {
                System.Threading.Thread t = new Thread(threadmethod);
                t.IsBackground = true;
                t.Start();
                for (int i = 0; i < 4; i++)
                {
                    Console.WriteLine("Main thread proc {0}",i);
                    System.Threading.Thread.Sleep(500);
                }
             
            }
            public static void threadmethod()
            {
                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("Thread method proc {0}",i);
                    System.Threading.Thread.Sleep(500);
                }
            }

        }
    }
    result:
    if u set background property true thread exits Immediately 
    Main thread proc 0
    Thread method proc 0
    Main thread proc 1
    Thread method proc 1
    Thread method proc 2
    Main thread proc 2
    Thread method proc 3
    Main thread proc 3
    Thread method proc 4
    Press any key to continue . . .

    i

    No comments

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728