![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
/*ThreadPlayaround实例
介绍如何处理线程,非实际编程问题*/
using System;
using System.Threading;
namespace ConsoleThreadTest
{
class Program
{
static int interval;
static void Main(string[] args)
{
Console.Write("Interval to display result at?>");
interval = int.Parse(Console.ReadLine());
Thread.CurrentThread.Name = "Main";
ThreadStart workerStart = new ThreadStart(StartMethod);
Thread workerThread = new Thread(workerStart);
workerThread.Name = "Worker";
//workerThread.Priority = ThreadPriority.Highest;//定义一个高于主线程优先级的优先级别
workerThread.Start();
Thread.Sleep(1000);
DisplayNumbers();
Console.WriteLine("Main Thread finished");
Console.ReadLine();
}
static void DisplayNumbers()
{
System.Threading.Thread thisThread = Thread.CurrentThread;
string name = thisThread.Name;
Console.WriteLine("Starting Thread"+name);
Console.WriteLine(name + ":CurrentCulture=" + thisThread.CurrentCulture);
for (int i = 1; i <=8* interval; i++)
{
if (i%interval == 0)
{
Console.WriteLine(name + ":count has reached" + i);
}
}
}
static void StartMethod() {
DisplayNumbers();
Console.WriteLine("Work Thread finished");
}
}
}