当前位置: 首页>>代码示例>>C#>>正文


C# Worker.RequestStop方法代码示例

本文整理汇总了C#中Worker.RequestStop方法的典型用法代码示例。如果您正苦于以下问题:C# Worker.RequestStop方法的具体用法?C# Worker.RequestStop怎么用?C# Worker.RequestStop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Worker的用法示例。


在下文中一共展示了Worker.RequestStop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main()
    {
        // 创建线程对象。这不会启动该线程。
        Worker workerObject = new Worker();
        Thread workerThread = new Thread(workerObject.DoWork);

        // 启动辅助线程。
        workerThread.Start();
        Console.WriteLine("main thread: Starting worker thread...");

        // 循环直至辅助线程激活。
        while (!workerThread.IsAlive);

        // 为主线程设置 1 毫秒的休眠,
        // 以使辅助线程完成某项工作。
        Thread.Sleep(1);

        // 请求辅助线程自行停止:
        workerObject.RequestStop();

        // 使用 Join 方法阻塞当前线程,
        // 直至对象的线程终止。
        workerThread.Join();
        Console.WriteLine("main thread: Worker thread has terminated.");
    }
开发者ID:jetlive,项目名称:skiaming,代码行数:25,代码来源:ThreadStartStop.cs

示例2: Main

    static void Main()
    {
        // Create the thread object. This does not start the thread.
        Worker workerObject = new Worker();
        Thread workerThread = new Thread(workerObject.DoWork);

        // Start the worker thread.
        workerThread.Start();
        Console.WriteLine("main thread: Starting worker thread...");

        // Loop until worker thread activates.
        while (!workerThread.IsAlive) ;

        // Put the main thread to sleep for 1 millisecond to
        // allow the worker thread to do some work:
        Thread.Sleep(1);

        // Request that the worker thread stop itself:
        workerObject.RequestStop();

        // Use the Join method to block the current thread
        // until the object's thread terminates.
        workerThread.Join();
        Console.WriteLine("main thread: Worker thread has terminated.");
    }
开发者ID:karthikkumsi,项目名称:FTDI_Test-app,代码行数:25,代码来源:Form1.cs

示例3: WaitMessage

        public static int WaitMessage()
        {

            // Create the thread object. This does not start the thread.
            Worker workerObject = new Worker();
            workerObject.m_connection = m_connection;

            Thread workerThread = new Thread(workerObject.DoWork);

            // Start the worker thread.
            workerThread.Start();
            MessageBox.Show("main thread: Starting worker thread...");

            // Loop until worker thread activates.
            while (!workerThread.IsAlive) ;

            // Put the main thread to sleep for 1 millisecond to
            // allow the worker thread to do some work:
            Thread.Sleep(1);

            // Request that the worker thread stop itself:
            workerObject.RequestStop();

            // Use the Join method to block the current thread 
            // until the object's thread terminates.
            workerThread.Join();
            MessageBox.Show("main thread: Worker thread has terminated.");
            
            //while (m_wait_message)
            //{ 
            //    MessageBox.Show("WaitMessage");
            //}

            /*


            //while (m_wait_message)
            while (true)
            {


            } */

            return (0);
        }
开发者ID:bigtonylewis,项目名称:rabbit4mt4,代码行数:45,代码来源:UnmanagedExports.cs


注:本文中的Worker.RequestStop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。