19 June 2014

Simple Threading in C#.net

Today ,we will discuss about small threading program in C#.Net

using System;
using System.Threading;

class ThreadTest
{
    public void Run()
    {
        Console.WriteLine("Run Called");
        Thread.Sleep(10000);
    }

    public static void Main(String[] args)
    {
        ThreadTest b = new ThreadTest();
        Thread t = new Thread(new ThreadStart(b.Run));
        t.Start();

        Console.WriteLine("Thread 't' started.");
        Console.WriteLine("There is no telling when " +
                          "'Run' will be invoked. ");

        t.Join();

        Console.WriteLine("Thread 't' has ended.");
    }
}

No comments: