C#多线程解决程序卡顿问题

描述:

在 C# 中,System.Threading.Thread 类用于线程的工作。它允许创建并访问多线程应用程序中的单个线程。进程中第一个被执行的线程称为主线程。

案例:

static void Main(string[] args)
{
int num = 100;
for (int i = 0; i < num; i++)
{
//无参的多线程
noParmaThread();

}
}
private static void StartThread()

{
Console.WriteLine("------开始了新线程------");
Thread.Sleep(2000);//wait
Console.WriteLine("------线程结束------");
}

/// <summary>
///不需要传递参数
/// </summary>
private static void noParmaThread()
{
ThreadStart threadStart = new ThreadStart(StartThread);
var thread = new Thread(threadStart);
thread.Start();//开始线程
}

 

posted @ 2019-07-22 11:50  haishu  阅读(3864)  评论(1编辑  收藏  举报