
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to create a thread in C#?
Threads are lightweight processes. A thread is defined as the execution path of a program. Threads are created by extending the Thread class. The extended Thread class then calls the Start() method to begin the child thread execution.
Example of Thread: One common example of use of thread is implementation of concurrent programming by modern operating systems. Use of threads saves wastage of CPU cycle and increase efficiency of an application.
The following is an example showing how to create a thread.
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
- Related Articles
- How to create a thread in Java
- How to create a thread in android?
- C# Program to create a Simple Thread
- C# Program to Create a Thread Pool
- How to create a thread in JShell in Java 9?
- How to get the thread ID from a thread in C#?
- How to create a thread by using anonymous class in Java?
- How to create a thread using method reference in Java?\n
- How to create a thread using lambda expressions in Java?\n
- How to check whether a thread is a background thread or not in C#
- How to create a thread without implementing the Runnable interface in Java?
- How to check current state of a thread in C#?
- What method is used to create a daemon thread in Java?
- Check if a thread belongs to managed thread pool or not in C#
- C# Program to Kill a Thread

Advertisements