zoukankan      html  css  js  c++  java
  • 一个多线程协助工作

      public class Worker
        {
            
    // This method will be called when the thread is started.
            public void DoWork()
            {  
                Console.WriteLine(
    "主线程成功启动!");
                
    while (!_shouldStop)
                {
                   
                    Console.WriteLine( DateTime.Now.ToString(
    "yyyyMMddHHmmss")+":主进程正在工作!" );
                    guard.guardId 
    = true;
                    GetNewEmails();
                    System.Threading.Thread.Sleep(
    1000 * refreshinterval);

                }
                Console.WriteLine(
    "主线程关闭!");
            }
            
    public void RequestStop()
            {
                _shouldStop 
    = true;
            }
            
    public void RequestOpen()
            {
                _shouldStop 
    = false;
            }
            
    public bool shouldStop
            {
                
    get { return _shouldStop; }
                
    set { _shouldStop = value; }
            }
        
            
    private bool _shouldStop = false;
    }
    guard.cs
        static class Program
        {  

          
            
    /// <summary>
            
    /// 应用程序的主入口点。
            
    /// </summary>
            static public  Worker workerObject = new Worker();
            
    static public  guard guardobject = new guard();
            
    static public  Thread workerThread = null;
            
    static public  Thread  guardThread=null;
            
    static void Main()
            {
               workerThread 
    = new Thread(workerObject.DoWork);
               guardThread 
    = new Thread(guard.guardThread);
               workerThread.Start();
               guardThread.Start();
            }
        
        }
  • 相关阅读:
    [原创]ExtAspNet秘密花园(二) — 一切从头开始
    使用领域定义建模语言来提高生产力
    报表控件团队成立了!!
    常见的程序语言分类的区别(简要说明)
    怎样做一名“专业”的程序员?
    推荐一个计数器网站
    在c中嵌入sql操作PostgreSQL
    让Visual C++ 2005 Express Edition也可以开发windows应用程序
    使用PowerDesigner进行代码生成
    sdmagazine与Dr. Dobb's Journal合并了?
  • 原文地址:https://www.cnblogs.com/gwazy/p/1596765.html
Copyright © 2011-2022 走看看