FileSystemWatcher OnChanged事件需要重新加入UI线程 [英] FileSystemWatcher OnChanged event needs to rejoin UI thread

查看:72
本文介绍了FileSystemWatcher OnChanged事件需要重新加入UI线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦OnChanged事件完成,如何在FileSystemWatcher中获取OnChanged事件以在UI线程上调用方法?

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

或者,仅出于知识上的考虑,如何使OnChanged事件完全在UI线程上运行?

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

推荐答案

如果您希望 FileSystemWatcher 在UI线程上引发事件,并且您正在使用Windows窗体,请设置 SynchronizingObject 到控件或窗体.如果您使用的是WPF(没有实现 ISyncronizeInvoke 的任何功能),则此功能就没有用.例如,通常您只需通过 Application.Current.Dispatcher.Invoke 在Dispatcher上调用Invoke.

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.

这篇关于FileSystemWatcher OnChanged事件需要重新加入UI线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆