Tuesday, July 8, 2014

Threads in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
/* thread is a light weight process,A process consists of many threads,Threads help us to accomplish the task of multitasking,*/
/* the various thread functions are Start(),Sleep(milliseconds),Abort(),Suspend(),Resume()*/
namespace ConsoleApplication5
{
    class thread    {
        static void Main(string[] args)
        {
            Thread t1 = new Thread(fun1);
            Thread t2 = new Thread(fun2);
            t1.Start();
            t2.Start();
           

           
            Console.Read();
        }

        public static void fun1()
        {
            for (int i = 0; i < 5000; i++)
            {
                Console.WriteLine("Hi");
                Thread.Sleep(2000);
            }
        }
        public static void fun2()
        {
            for (int i = 0; i < 500; i++)
            {
                Console.WriteLine("hello");
                Thread.Sleep(1000);
            }
        }
    }
}

No comments:

Post a Comment