I have a FileSystemWatcher that react on the Changed event.
I want to open the file, read its content display it in a textbox and hide the popup that has been create
The problem is that extendedNotifyIcon_OnHideWindow
is being executed on a thread other than the UI thread. You will need to use the Dispatcher
for that part as well. Also, I would not create a dedicated thread just to wait one second. You could easily refactor that part into a System.Threading.Timer
. Here is my refactored version.
txtLog.Dispatcher.Invoke(
(Action)(() =>
{
txtLog.Text = dataToDisplay;
extendedNotifyIcon_OnShowWindow();
new Timer(
(state) =>
{
button1.Dispatcher.BeginInvoke(
(Action)(() =>
{
extendedNotifyIcon_OnHideWindow();
}), null);
}, null, 1000, Timeout.Infinite);
}));