FileSystemWatcher OnChanged event needs to rejoin UI thread

我怕爱的太早我们不能终老 提交于 2020-12-27 06:18:06

问题


How can I get the OnChanged event in a FileSystemWatcher to invoke a method on the UI thread once the OnChanged event is completed?

Or, just for the sake of knowledge, how can I get the OnChanged event to run entirely on the UI thread?


回答1:


If you want FileSystemWatcher to raise events on the UI thread and you are using Windows Forms, set the SynchronizingObject to a Control or Form. This isn't as useful if you are using WPF, where there isn't anything that implements ISyncronizeInvoke. You typically just call Invoke on the Dispatcher via Application.Current.Dispatcher.Invoke, for example.



来源:https://stackoverflow.com/questions/28036423/filesystemwatcher-onchanged-event-needs-to-rejoin-ui-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!