title: Invoke event on MainThread from worker thread
body: <p>I'm having trouble invoking an event from a secondary thread in the main thread. The event handler is not executed on main thread. Can anyone give me some pointers on what I'm doing wrong. </p>
  
  <p>Thanks</p>
  
  <pre><code>namespace ThreadSyncExample
  {
    class Program
    {
      static void Main(string[] args)
      {
        Console.WriteLine("MainThread: " + System.Threading.Thread.CurrentThread.ManagedThreadId);
  
        Execute execThe = new Execute();
        execThe.FinishedThread += (src, arg) =&gt;
        {
          //This shoould be executed on MainThread right?
          Console.WriteLine("Thread Id: " + System.Threading.Thread.CurrentThread.ManagedThreadId);
        };
  
        execThe.Run();
        Console.ReadKey();
      }
  
    }
  
  
    class Execute
    {
      public void Run()
      {
        Thread exec = new Thread(() =&gt;
        {
          Console.WriteLine("Worker Thread : " + System.Threading.Thread.CurrentThread.ManagedThreadId);
          OnFinishedThread();
        });
  
        exec.Start();
      }
  
      public event EventHandler FinishedThread;
      protected virtual void OnFinishedThread()
      {
        if (null != FinishedThread)
        {
          EventArgs args = new EventArgs();
          FinishedThread(this, EventArgs.Empty);
        }
      }
    }
  }
  </code></pre>