get filesystemwatcher events to occur on main UI thread

后端 未结 2 980
孤街浪徒
孤街浪徒 2020-12-11 08:14

Can i get filesystemwatcher events to occur on the main UI thread ?. Currently file changes are fired off on their own threads.

2条回答
  •  悲&欢浪女
    2020-12-11 09:07

    Simply set the FileSystemWatcher.SynchronizingObject property to the form instance. Same thing as calling BeginInvoke() but done automatically for you. Boilerplate code:

    public Form1() {
        InitializeComponent();
        fileSystemWatcher1.SynchronizingObject = this;
    }
    

提交回复
热议问题