• Top Posts

    creating a thread with thread class

    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.Start();
                for (int i = 0; i < 4; i++)
                {
                    Console.WriteLine("Main thread proc {0}",i);
                    System.Threading.Thread.Sleep(500);
                }
               t.join();
            }
            public static void threadmethod()
            {
                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("Thread method proc {0}",i);
                    System.Threading.Thread.Sleep(500);
                }
            }

        }
    }


    result:
    Main thread proc 0
    Thread method proc 0
    Main thread proc 1
    Thread method proc 1
    Main thread proc 2
    Thread method proc 2
    Main thread proc 3
    Thread method proc 3
    Thread method proc 4
    Thread method proc 5
    Thread method proc 6
    Thread method proc 7
    Thread method proc 8
    Thread method proc 9
    Press any key to continue . . .

    No comments

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728