zoukankan      html  css  js  c++  java
  • System.Timers.Timer 嵌套 System.Windows.Forms.Timer的问题

    如题“System.Timers.Timer 嵌套 System.Windows.Forms.Timer的问题”,最近在项目中在类uc_Map中启用了System.Timers.Timer,并在Timer的Timer_Elapsed方法中需要启动或停止GMapMarkerDirection markerPlane类中的System.Windows.Forms.Timer,但是并没用在uc_Map启动/停止成功,经排查,需要在启动或停止markerPlane中的方法时需要加委托Invoke,如下:

    uc_Map中的Timer_Elapsed方法:
    
    
    this.Invoke(new Action(delegate
                        {
                            if (isWarnData)
                            { markerPlane.StartFlash(); }
                            else
                                markerPlane.StopFlash();
                        }));
    

    markerPlane类中的方法:

     /// <summary>
            /// 开始闪烁
            /// </summary>
            public void StartFlash()
            {
                if (bIsFlash == false)
                {
                    flashTimer.Start();
                    bIsFlash = true;
                }
            }
    
            /// <summary>
            /// 停止闪烁
            /// </summary>
            public void StopFlash()
            {
                if (bIsFlash == true)
                {
                    flashTimer.Stop();
                    if (FlashPen != null)
                    {
                        FlashPen.Dispose();
                        FlashPen = null;
                    }
    
                    if (this.Overlay.Control.InvokeRequired)
                    {
                        this.Overlay.Control.Invoke(new Action(delegate
                        {
                            this.Overlay.Control.Refresh();
                        }));
                    }
                    else
                        this.Overlay.Control.Refresh();
    
                    bIsFlash = false;
                }
            }
    

      

    这样就能正常启动/停止第二个Timer

  • 相关阅读:
    洛谷P3275 [SCOI2011]糖果
    2018年12月30&31日
    洛谷P4114 Qtree1
    洛谷P4116 Qtree3
    洛谷P4315 月下“毛景树”
    洛谷P1505 [国家集训队]旅游
    洛谷P2253 好一个一中腰鼓!
    CF616D Longest k-Good Segment
    洛谷P3979 遥远的国度
    洛谷P2486 [SDOI2011]染色
  • 原文地址:https://www.cnblogs.com/Jins/p/5322070.html
Copyright © 2011-2022 走看看