Please explain why it does not work. On the form in Load_Form following code:

  Timer timer = new Timer(); public Form1() { InitializeComponent(); } private async void Form1_Load(object sender, EventArgs e) { await Task.Run(() => { SetTimer(); }); } public void SetTimer() { timer = new Timer(); timer.Interval = 1000; timer.Tick += new EventHandler(timer_Tick); timer.Enabled = true; } void timer_Tick(object sender, EventArgs e) { label1.Text += 1; } 

The timer_Tick method timer_Tick not work, why?

  • one
    and the Timer you have from what namespace? - 4per
  • @ 4per System.Windows.Forms; - Winteriscoming
  • remove 'await Task.Run (() =>'. - Leonid Malyshev
  • Here is about the behavior of various timers: ru.stackoverflow.com/a/696486/10105 - VladD

1 answer 1

System.Windows.Forms.Timer does not support the use of multiple threads. This is clearly written in the documentation:

... This is a Windows environment where the UI threads are used to perform processing. It can be used to always connect to the user.

Depending on the situation, you can try: