title: SynchronizationContext.Post to UI Method
body: <p>I'm working with web services so its necessary for me to extend session length/reconnect and get large datasets back etc.  Sometimes this can be lengthy so I wanted it in an separate thread that updates the UI asynchronously.</p>
  
  <p>I can't seem to get my head around using the synchronizationContext to invoke a method on my UI thread.  I have it whereby I have passed my UIThread context to my thread and now I want to update some labels etc on UI Thread.  I've read tons of posts but none seem to explain how to simply pass some parameters back to a method, or maybe they do but i'm too tired/stupid to have seen it.</p>
  
  <p>//On main UI Thread</p>
  
  <pre><code>public void updateConnStatus(string conn_name, bool connected)
  {
          switch (conn_name)
          {
              case "Conn" : if (connected == true){ //do something} break;
  </code></pre>
  
  <p>//on separate Thread</p>
  
  <pre><code>uiContext.Post( //something to do with delegates in here that eludes me );
  </code></pre>
  
  <p>if someone could simply explain how I link the sendOrPostCallBack to the original method I would be very grateful. </p>
  
  <p>Thanks</p>
  
  <p>Edit:</p>
  
  <p>I managed to get the code to run and try to fire the event, it populates my custom eventArgs okay but either its saying that updateUIConnStatus has not been instantiated, needs more investigation :o</p>
  
  <pre><code>public void updateUIThread(string conn, bool connected)
      {
         uiContext.Post(new SendOrPostCallback((o) =&gt; { updateConnStatus(this, new MyEventArgs&lt;String, Boolean&gt;(conn, connected)); }), null);
      }
  
  public class MyEventArgs&lt;T, U&gt; : EventArgs
      {
          private T _val1; private U _val2;
          public  MyEventArgs(T value1, U value2) { _val1 = value1; _val2 = value2; }
          public T val1 { get { return _val1;} }
          public U val2 { get {return _val2;} }
      }
  
  public event EventHandler&lt;MyEventArgs&lt;String, Boolean&gt;&gt; updateConnStatus = Delegate {};
  </code></pre>
  
  <p>//on UI Thread Now</p>
  
  <pre><code> public void updateConnStatus(object sender, MyEventArgs&lt;String,Boolean&gt; e)
      {
          switch (e.val1)
          {
              case "Conn1" :
                  if (e.val2 == true)
                  {
  </code></pre>