即使你沒有編寫多線程應用程序的經驗
a
顧名思義
Thread thread
其中的 Count 是將要被新線程執行的函數
b
c
它的意思就是讓一個正在運行的線程休眠一段時間
d
這個用不著解釋了
thread
e
Thread類的Suspend方法用來掛起線程
if (thread
{
thread
}
f
用來恢復已經掛起的線程
if (thread
{
thread
}
下面將列出一個例子
using System;
using System
// Simple threading scenario: Start a static method running
// on a second thread
public class ThreadExample
{
// The ThreadProc method is called when the thread starts
// It loops ten times
// the rest of its time slice each time
public static void ThreadProc()
{
for (int i =
{
Console
// Yield the rest of the time slice
Thread
}
}
public static void Main()
{
Console
// The constructor for the Thread class requires a ThreadStart
// delegate that represents the method to be executed on the
// thread
Thread t = new Thread(new ThreadStart(ThreadProc));
// Start ThreadProc
// any processor time until the main thread yields
// the Thread
t
//Thread
for (int i =
{
Console
Thread
}
Console
t
Console
Console
}
}
此代碼產生的輸出類似如下內容
Main thread: Start a second thread
Main thread: Do some work
ThreadProc:
Main thread: Do some work
ThreadProc:
Main thread: Do some work
ThreadProc:
Main thread: Do some work
ThreadProc:
Main thread: Call Join()
ThreadProc:
ThreadProc:
ThreadProc:
ThreadProc:
ThreadProc:
ThreadProc:
Main thread: ThreadProc
From:http://tw.wingwit.com/Article/program/net/201311/14673.html