Can i get filesystemwatcher events to occur on the main UI thread ?. Currently file changes are fired off on their own threads.
4
votes
2 Answers
13
votes
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;
}
Control.Invoke()
, WPF useDispatcher.BeginInvoke()
from your event handler to pass the event off to your UI thread. – Steve