Refresh UI with a Timer in WPF (with BackgroundWorker?)

前端 未结 2 909
半阙折子戏
半阙折子戏 2021-01-04 12:33

We have an application in WPF that shows data via ObservableCollection. After 5 minutes, I want to refresh the data.

I thought I could use the System.Timers.Ti

相关标签:
2条回答
  • 2021-01-04 12:42

    This answer explains the problem with using the Timer vs DispatcherTimer when updating the UI. https://stackoverflow.com/a/2258909/1698182

    I have not tried this but for periodic work items that will use a thread do the bulk of the work this looks like it will do the trick. http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj248676.aspx

    0 讨论(0)
  • 2021-01-04 12:48

    Why not use a DispatcherTimer? That will "tick" in the dispatcher thread already.

    Beyond that, it's hard to say what's wrong just from your description of "there's a problem with the threads".

    0 讨论(0)
提交回复
热议问题