简体   繁体   English

获取要在主UI线程上发生的filesystemwatcher事件

[英]get filesystemwatcher events to occur on main UI thread

Can i get filesystemwatcher events to occur on the main UI thread ?. 我可以在主UI线程上获得filesystemwatcher事件吗? Currently file changes are fired off on their own threads. 目前,文件更改将在其自己的线程上触发。

Simply set the FileSystemWatcher.SynchronizingObject property to the form instance. 只需将FileSystemWatcher.SynchronizingObject属性设置为表单实例即可。 Same thing as calling BeginInvoke() but done automatically for you. 与调用BeginInvoke()相同但为您自动完成。 Boilerplate code: Boilerplate代码:

public Form1() {
    InitializeComponent();
    fileSystemWatcher1.SynchronizingObject = this;
}
this.BeginInvoke((MethodInvoker)(() => SomeMethod())); // Check files in the Main thread otherwise threading issues occur 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM