title: How to pass a single event from thread up to GUI form thread?
body: <p>I am new to C# and am having trouble figuring out how to pass an event from a thread up to the GUI form thread.  Any help would be appreciated.  All of the examples I find are WAY too complicated.  I just want to start with one event from the treat up to the GUI and have the GUI do something (right now, anything).</p>
  
  <pre><code>namespace testEvents
  {
  public delegate void StuffHappenedDel( MessageEventArgs e);
  
  public partial class Form1 : Form
  {
  
  
      workerThread thread;
      int j = 0;
      public Form1()
      {
          InitializeComponent();
          thread = new workerThread();
          thread.Start();
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          thread.Stop();
      }
  
  
  
      private void StuffHappenedDel(Object seder, EventArgs e)
      {
          j++;
      }
  
  
  }
  
  public class workerThread
  {
      Thread worker;
      private bool _quit = false;
  
      /*  I don't think this next line is correct*/
      public event StuffHappenedDel StuffHappened;
  
  
      protected virtual void OnStuffHappened(MessageEventArgs e)
      {
          if (StuffHappened != null)
              StuffHappened( e);
      }
  
  
      public void Start()
      {
          ThreadStart start = new ThreadStart(Run);
          worker = new Thread(start);
          worker.Start();
      }
  
      private void Run()
      {
          int i = 0;
          while (!_quit)
          {
              Thread.Sleep(1000);
              i++;
              OnStuffHappened(new MessageEventArgs(false, "it worked!"));
              Console.WriteLine(string.Format("Slept {0} seconds.",i));
          }
          Console.WriteLine("Thread exiting");
      }
  }
  
  
  public class MessageEventArgs : EventArgs
  {
      public MessageEventArgs(bool Error, string message)
      {
          IsError = Error;
          Message = message;
      }
  
      public bool IsError { get; set; }
      public string Message { get; set; }
  }
  </code></pre>
  
  <p>}</p>