Search code examples
c#winformstimer

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


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 need (xxx ms) and write it on the form control to show.

But when I access the listview, I get an cross thread error.

Any ideas?


Solution

  • If you want to acces a control from a thread other than the main UI thread, you need to use the Invoke method on the control you want to access.