我有一个线程,我试图在OnStop方法中停止,有人可以演示如何终止/停止一个线程:
/// <summary>
/// OnStop: Put your stop code here
/// - Stop threads, set final data, etc.
/// </summary>
protected override void OnStop()
{
base.OnStop();
}
考虑到这一点,开头如下:
/// <summary>
/// OnStart: Put startup code here
/// - Start threads, get inital data, etc.
/// </summary>
/// <param name="args"></param>
protected override void OnStart(string[] args)
{
Thread MyThread = new Thread(new ThreadStart(MyThreadStarter));
MyThread.Start();
base.OnStart(args);
}
private void MyThreadStarter()
{
realtime obj = new realtime();
obj.Starter();
}
答案 0 :(得分:2)
答案 1 :(得分:0)
objThread.Abort();
在OnStop()
方法...