How can i use a BackgroundWorker with a timer tick?

后端 未结 6 734
一向
一向 2020-12-06 04:10

Decided to not use any timers. What i did is simpler.

Added a backgroundworker. Added a Shown event the Shown event fire after all the constructor have been loaded.

6条回答
  •  长情又很酷
    2020-12-06 04:41

    In my case I was using a BackgroundWorker ,a System.Timers.Timer and a ProgressBar in WinForm Application. What I came across is on second tick that I will repeat the BackgroundWorker's Do-Work I get a Cross-Thread Exception while trying to update ProgressBar in ProgressChanged of BackgroundWorker .Then I found a solution on SO @Rudedog2 https://stackoverflow.com/a/4072298/1218551 which says that When you initialize the Timers.Timer object for use with a Windows Form, you must set the SynchronizingObject property of the timer instance to be the form.

    systemTimersTimerInstance.SynchronizingObject = this; // this = form instance.
    

    http://msdn.microsoft.com/en-us/magazine/cc164015.aspx

提交回复
热议问题