Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get filesystemwatcher events to occur on main UI thread

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

like image 770
user1438082 Avatar asked Dec 06 '22 02:12

user1438082


1 Answers

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;
}
like image 166
Hans Passant Avatar answered Dec 10 '22 11:12

Hans Passant