How to access a form-control from System.Timers.Timer (cross thread problem)

后端 未结 3 2021
离开以前
离开以前 2020-12-22 04:46

I use the system.timers.timer for my service.

Now I build a test-form in which I use it too. In the timer_Elapsed Event I do some work and want to stop the timer it

3条回答
  •  清歌不尽
    2020-12-22 05:06

    Your method should look like:

    public void foo(int value, string message)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new Action(foo), value, message);
            }
            else
            {
                // Stop the timer 
            }
        }
    

提交回复
热议问题