3 回答

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

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