title: How to execute code in the GUI Thread?
body: <p>I have a FileSystemWatcher that react on the Changed event.</p>
  
  <p>I want to open the file, read its content display it in a textbox and hide the popup that has been created after 1 sec. The code almost work but something fail when hiding the popup.</p>
  
  <p>Here is a snippet of the code :</p>
  
  <pre><code>       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();
          });
  </code></pre>
  
  <p>As you can see, I use the Invoke to set the text because the event is in a different thread (FileSystemWatcher). But to hide the windows the extendedNotifyIcon_OnHideWindow() is not executed in the thread of the GUI. How can I execute it in the GUI thread?</p>