
- 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
C# Program to create a Simple Thread
To create a thread, I have created a function −
public void myThread() { for (int i = 0; i < 3; i++) { Console.WriteLine("My Thread"); } }
The above function is called to create a thread and a new ThreadStart delegate is created −
Demo d = new Demo(); Thread thread = new Thread(new ThreadStart(d.myThread));
Example
Create a simple thread using the following code.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; class Demo { public void myThread() { for (int i = 0; i < 3; i++) { Console.WriteLine("My Thread"); } } } class NewThread { public static void Main() { Demo d = new Demo(); Thread thread = new Thread(new ThreadStart(d.myThread)); thread.Start(); Console.Read(); } }
Output
My Thread My Thread My Thread
- Related Articles
- C# Program to Create a Thread Pool
- How to Create a Simple Program in C++?
- Golang Program to Create a Simple Class?
- How to create a thread in C#?
- C# Program to Kill a Thread
- C# Program to Pause a Thread
- Haskell Program to create a simple recursive function
- C# Program to pass Parameter to a Thread
- C/C++ program to make a simple calculator?
- How to create a thread in Java
- How to create a thread in android?
- C# Program to display priority of Thread
- How to create a simple MySQL function?
- C# Program to Check status of Current Thread
- C# Program to display name of Current Thread

Advertisements