سؤال

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

هل كانت مفيدة؟

المحلول

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;
}

نصائح أخرى

this.BeginInvoke((MethodInvoker)(() => SomeMethod())); // Check files in the Main thread otherwise threading issues occur 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top