title: The calling thread must be STA, because many UI components require this error In WPF. On form.show()
body: <p>Firstly I have read several answers to similar questions on the site but to be honest I find them a bit confusing (due to my lack of experience rather than the answers!). I am using a the FileSystemWatcher() class to monitor a folder for a file being created/changed. Once the event occurs I then want to load another form in the project. Instead of loading the form I get the error when the constructor on the new form is trying to execute. I am only using one thread - I'm not attempting to load the form under a different thread. My code is as follows</p>
  
  <pre><code> //MainWindow
   public static void FolderWatcher()
    {
          FileSystemWatcher fsWatcher = new FileSystemWatcher();
          fsWatcher.Path = "C:\\dump";
          fsWatcher.Filter = "*";
          fsWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
          | NotifyFilters.FileName | NotifyFilters.DirectoryName;
          fsWatcher.Created += new FileSystemEventHandler(OnChanged);
          fsWatcher.EnableRaisingEvents = true;    
    }
  
    public static void OnChanged(object source, FileSystemEventArgs e)
    {
         var imagePreview = new ImagePreview();
         imagePreview.Show();
    }
  
  
    //SecondForm
    public partial class ImagePreview : Window
    {
          public ImagePreview()
          {
                InitializeComponent(); //error occurs here
          }
    }
  </code></pre>
  
  <p>Hope you can help, many thanks in advance.</p>