|
using System;using System.Threading;
public class StaticThreads
{
//testing static threads
public static void Main1()
{
Thread myThread1 = new Thread(new
ThreadStart(StaticThreads.DoSomething));
Thread myThread2 = new Thread(new
ThreadStart(StaticThreads.DoSomething));
Thread myThread3 = new Thread(new
ThreadStart(StaticThreads.DoSomething));
myThread1.Name = "Thread 1";
myThread2.Name = "Thread 2";
myThread3.Name = "Thread 3";
Console.WriteLine("Press ENTER to start,");
Console.WriteLine("and ENTER again to stop.");
Console.ReadLine();
myThread1.Start();
Thread.Sleep(300);
myThread2.Start();
Thread.Sleep(300);
myThread3.Start();
Console.ReadLine();
myThread1.Abort();
myThread2.Abort();
myThread3.Abort();
}
public static void DoSomething()
{
while (true)
{
Console.WriteLine(Thread.CurrentThread.Name + DateTime.Now);
Thread.Sleep(1000);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Sergey is graduated as applied mathematician. He is specialized in custom development including parsing tools, client/server applications.
github: https://github.com/sergeystoyan
site: http://cliversoft.com