//线程属性
protected Thread workerThread;
protected bool isWorkerThreadStopped = true;
public void Initialize()
{
//初始化代码
}
public void Start()
{
isWorkerThreadStopped = false;
workerThread = new Thread(WorkerTask);
workerThread.IsBackground = true;
workerThread.Start();
}
public void Stop()
{
isWorkerThreadStopped = true;
}
protected virtual void WorkerTask()
{
while (!isWorkerThreadStopped)
{
//需要循环执行的代码
Thread.Sleep(1000);
}
}