How to enable a timer from a different thread/class

前端 未结 4 890
心在旅途
心在旅途 2020-12-21 05:27

Original post: How to access a timer from another class in C#

I tried everything.

-Event

-Invoke can\'t be done,because Timers don\'

4条回答
  •  失恋的感觉
    2020-12-21 06:26

    I accidently tried to use invoke again,this time it worked,but I'll accept your answer,DavidM.

        public bool TimerEnable
        {
            set
            {
                this.Invoke((MethodInvoker)delegate
                {
                    this.timer.Enabled = value;
                });
            }
        }
    
    
        public static void timerEnable()
        {
            var form = Form.ActiveForm as Form1;
            if (form != null)
                form.TimerEnable = true;
        }
    

提交回复
热议问题