Threads in C# programming
1. C# Threads Example 1
using System.Threading;
public class yyy
{
public void abc()
{
for ( int i = 0; i< =3;i++)
{
System.Console.Write(i + ” “);
}
}
public void pqr()
{
for ( int i = 0; i<=3;i++)
{
Thread.Sleep(1000);
System.Console.Write(i+ “…”);
}
}
}
public class zzz
{
public static void Main()
{
yyy a = new yyy();
Thread t = new Thread(new ThreadStart(a.abc));
Thread t1 = new Thread(new ThreadStart(a.pqr));
t.Start();
t1.Start();
}
}
2. Example 2 of threading in C Sharp (C#)
using System;
using System.Threading;
class App {
public static void Main() {
Console.WriteLine(” (Hit or Press Enter to terminate the sample)”);
Timer timer = new Timer(new TimerCallback(CheckStatus), null, 1, 2000);
Console.WriteLine(”Press Enter to close window”);
Console.Read();
}
// The callback method’s signature MUST match that of a System.Threading.TimerCallback
// delegate (it takes an Object parameter and returns void)
static void CheckStatus(Object state) {
Console.WriteLine(”Threads in C # sharp”);
}
}