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();//開始線程
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM