我有一个线程试图在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();
    }

最佳答案

从MS How to: Create and Terminate Threads (C# Programming Guide)检查此示例

关于c# - 如何使用OnStop方法(C#)终止线程,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6456477/

10-10 17:18