Thread example using CSharp dotnet

Thread example using CSharp dotnet

Threads in C# are having delegate functionality. We can do the parallel operations with the CPU. This memory will be work as system memory and application memory. This is one of the good DOTNET interview question.

Please give your valuable feedback on this post.. i need to enhance more on this topic.

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

namespace Threads
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ThreadProgram obj = new ThreadProgram();
                //doing delegate operation
                Thread objExample = new Thread(new ThreadStart(obj.Ranga));
                string str = objExample.ThreadState.ToString();
                //write thread state. 
                Console.WriteLine(str);//Unstarted
                objExample.Start();

                str = objExample.ThreadState.ToString();
                Console.WriteLine(str);//running
                System.Threading.Thread.Sleep(2000);
                
                Console.WriteLine("thread middle");
                objExample.Abort();//
                str = objExample.ThreadState.ToString();//Abortrequested
                Console.WriteLine(str);
                Console.WriteLine("thread ended");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception");
                Console.ReadLine();
            }
        }
    }
    class ThreadProgram
    {
        public void Ranga()
        {
            Console.WriteLine("thread started");
            Console.ReadLine();
        }
    }
}

Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar