I have a FileSystemWatcher that responds to a Changed event.
I want to open a file, read its contents, display it in a text box and hide the popup that was created after 1 second. The code almost works, but something fails to hide the popup.
Here is the code snippet:
txtLog.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() {
this.txtLog.Text = dataToDisplay;
extendedNotifyIcon_OnShowWindow();
Thread threadToClosePopup = new Thread(new ThreadStart((Action)delegate() {
Thread.Sleep(1000);
extendedNotifyIcon_OnHideWindow();
}));
threadToClosePopup.Start();
});
As you can see, I use Invoke to set the text, because the event is in a different thread (FileSystemWatcher). But to hide windows, extended NotifyIcon_OnHideWindow () is not executed in the GUI thread. How can I execute it in a GUI thread?
source
share