Thread.Start Method is responsible for a thread to be scheduled for execution. This method can be overloaded by passing different parameters to it.
- Start()
- Start(Object)
Start()
This method tells the operating system to change the state of the current instance to Running. Or in other words, due to this method the thread start its execution.
Syntax:
public void Start ();
Exceptions:
- ThreadStateException : If the thread has already been started.
- OutOfMemoryException : If there is not enough memory available to start a thread.
Example:
// C# program to illustrate the // use of Start() method using System; using System.Threading; class GThread { // Non-static method public void Job() { for (int X = 0; X < 4; X++) { Console.WriteLine(X); } } } // Driver Class public class GFG { // Main Method public static void Main() { // Creating object of GThread class GThread obj = new GThread(); // Creating and initializing a thread Thread thr = new Thread(new ThreadStart(obj.Job)); // Start the execution of Thread // Using Start() method thr.Start(); } } |
Output:
0 1 2 3
Start(Object)
This method tells the operating system to change the state of the current instance to Running. It passes an object containing data to be used by the method the thread executes. This parameter is optional.
Syntax:
public void Start (object parameter);
Here, parameter is an object that contains data to be used by the method the thread executes.
Exceptions:
- ThreadStateException : If the thread has already been started.
- OutOfMemoryException : If there is not enough memory available to start a thread.
- InvalidOperationException : If the thread was created using a ThreadStart delegate instead of a ParameterizedThreadStart delegate.
Example:
// C# program to illustrate the // use of Start(Object) method using System; using System.Threading; // Driver Class class GFG { // Main Method public static void Main() { // Creating object of GFG class GFG obj = new GFG(); // Creating and initializing threads Thread thr1 = new Thread(obj.Job1); Thread thr2 = new Thread(Job2); // Start the execution of Thread // Using Start(Object) method thr1.Start(01); thr2.Start("Hello") } // Non-static method public void Job1(object value) { Console.WriteLine("Data of Thread 1 is: {0}", value); } // Static method public static void Job2(object value) { Console.WriteLine("Data of Thread 2 is: {0}", value); } } |
Output:
Data of Thread 1 is: 1 Data of Thread 2 is: Hello
Reference:
Recommended Posts:
- Naming a thread and fetching name of current thread in C#
- How to check whether a thread is a background thread or not in C#
- C# | Check if a thread belongs to managed thread pool or not
- C# | Creating a synchronized (thread-safe) wrapper for a SortedList object
- C# | Check if StringCollection is synchronized (thread safe)
- Thread.CurrentThread Property in C#
- C# | Check if the BitArray is synchronized (thread safe)
- C# | Check if StringDictionary is synchronized (thread safe)
- C# | Check if ListDictionary is synchronized (thread safe)
- C# | Check if HybridDictionary is Synchronized (thread safe)
- C# | Check if Hashtable is synchronized (thread safe)
- C# | Check if ArrayList is Synchronized (thread safe)
- C# | Check if an array is synchronized (thread safe) or not
- C# | Creating a synchronized (thread-safe) wrapper for the Hashtable
- C# | Creating a synchronized (thread-safe) wrapper for the ArrayList
- C# | Thread Priority in Multithreading
- Lifecycle and States of a Thread in C#
- Main Thread in C#
- How to Terminate a Thread in C#
- Suspending the current thread for the specified amount of time in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

