Test foreground / worker behaviors : Background Thread : Thread C# Examples


C# Examples » Thread » Background Thread »

 

Test foreground / worker behaviors









    
using  System;
using  System.Threading;

class  MainClass
{
    static  void  MyThreadProc()
    {
        Thread.CurrentThread.Name  =  "TheSecondaryThread";
        Thread  secondaryThread  =  Thread.CurrentThread;
        Console.WriteLine("Name?  {0}",  secondaryThread.Name);
        Console.WriteLine("Alive?  {0}",  secondaryThread.IsAlive);
        Console.WriteLine("Priority?  {0}",  secondaryThread.Priority);            
        Console.WriteLine("State?  {0}",  secondaryThread.ThreadState);
        Console.WriteLine();

        for(int  i  =  0;  i  <  1000;  i  ++)
        {
            Console.WriteLine("Value  of  i  is:  {0}",  i);
            Thread.Sleep(5);
        }
    }

    [MTAThread]
    static  void  Main(string[]  args)
    {
        Thread  secondaryThread  =  new  Thread(new  ThreadStart(MyThreadProc));
        secondaryThread.Priority  =  ThreadPriority.Highest;
        
        secondaryThread.IsBackground  =  true;
        secondaryThread.Start();
    }
}
    
   
  
   



Output

Name? TheSecondaryThread
Alive? True
Priority? Highest
State? Background

Value of i is: 0


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» Background Thread