Threads Lightweight Processes होते हैं। एक Thread को Program के Execution Path के रूप में Define किया जाता है। Threads, Thread Class को Extend करके Create की जाती हैं। Extended Thread Class फिर Child Thread Execution शुरू करने के लिए Start() Method को Call करती है।
Thread का Example: Thread के उपयोग का एक Common Example Modern Operating Systems द्वारा Concurrent Programming का Implementation है। Threads के उपयोग से CPU Cycle की Wastage बचती है और Application की Efficiency बढ़ती है।
निम्न Example दर्शाता है कि Thread कैसे Create करें।
Example
using System; using System.Threading; namespace Demo { class Program { public static void ThreadFunc() { Console.WriteLine("Child thread starts"); } static void Main(string[] args) { ThreadStart childref = new ThreadStart(ThreadFunc); Console.WriteLine("In Main: Creating the Child thread"); Thread childThread = new Thread(childref); childThread.Start(); Console.ReadKey(); } } }Output
In Main: Creating the Child thread Child thread starts