Foreground Threads And Thread IDs in C#



Being a foreground thread means that the process cannot be stopped until it (and all other foreground threads) are stopped.
The quantum is the length of time a thread gets to run before the system will consider scheduling another thread on that processor.
The thread priority determines the pecking order within all ready to run, waiting for threads.

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using System.Threading;  
namespace ForegroundThreadsAndThreadIDs  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            for (int i = 0; i < Environment.ProcessorCount; i++)  
            {  
                Thread thread = new Thread(DefferentThread);  
                Thread.Sleep(1000);  
                thread.Start(i);  
            }  
            Console.WriteLine("This is MainThread");  
        }  
        static void DefferentThread(object threadID)  
        {  
            while (true)  
            {  
                Thread.Sleep(1000);  
                Console.WriteLine("This is DefferentThread:{0}-{1}", threadID, 
      Thread.CurrentThread.ManagedThreadId);  
            }  
        }  
    }  
}  
This is DefferentThread:0-3
This is DefferentThread:1-4
This is DefferentThread:0-3
This is DefferentThread:1-4
This is DefferentThread:2-5
This is MainThread
This is DefferentThread:0-3
This is DefferentThread:3-6
This is DefferentThread:1-4
This is DefferentThread:1-4
This is DefferentThread:3-6
This is DefferentThread:2-5
This is DefferentThread:0-3

0 Comment's

Comment Form