Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
Advertisements
