Helper methods for working with the WPF Dispatcher
anonymous methods to the rescue! I saw somebody griping about this syntax recently on a blog and found it unfortunate they were dissimenating this. The cleaner new and happy way to define a delegate, is quite simply:

The method signature without a name or types, so for example:

Sum(int a, int b)


becomes:

(a, b)


Follow this with our trusty lambda operator =&gt; and then our method body! This may be in a statement block between our trusty {} or just in a single line the same way you can put a single line after an if or while etc.

So in conclusion there are 3 ways to create a method:

Standard (must be declared as class member level):

public int Sum(int a, int b)
{
  return a+b;
}


Delegate (can be declared and instantiated as a method local):

delegate(int a, int b)
{
  return a+b; // god help me if this syntax is correct, I haven't created a delegate in years
}


Anonymous method (can be declared and instantiated as a method local):

(a, b) =&gt; { return a+b; };


Back to your example...

ThreadContext.InvokeOnUiThread(
    delegate()
    {
        MessageBox.Show("Hello world!");
    });


In anonymous method format becomes:

ThreadContext.InvokeOnUiThread(() =&gt; { MessageBox.Show("Hello world!"); });


Or if you prefer:

Action actionToInvokeOnUiThread = () =&gt; { MessageBox.Show("Hello world!"); };
ThreadContext.InvokeOnUiThread(actionToInvokeOnUiThread);