3 回答

TA貢獻1808條經(jīng)驗 獲得超4個贊
/// <summary>
/// 簡單的 線程執(zhí)行的 方法.
///
/// 這個方法是 靜態(tài)的
/// </summary>
public static void ThreadFunc()
{
// 線程停止運行的標志位.
Boolean done = false;
// 計數(shù)器
int count = 0;
while (!done)
{
// 休眠1秒.
Thread.Sleep(1000);
// 計數(shù)器遞增
count++;
// 輸出.
Console.WriteLine("[靜態(tài)]執(zhí)行次數(shù):{0}", count);
}
}
/// <summary>
/// 啟動線程的代碼.
/// </summary>
public static void StartThread()
{
ThreadStart ts = new ThreadStart(ThreadFunc);
Thread t = new Thread(ts);
// 啟動.
t.Start();
}

TA貢獻1840條經(jīng)驗 獲得超5個贊
引入名稱空間
using System.Threading;
然后使用Thread對象調(diào)用方法
例如
do{
方法
Thread.Sleep(2000);
}
while(條件)
- 3 回答
- 0 關(guān)注
- 2051 瀏覽
添加回答
舉報