Same function, variable parameters and types with lambda In my current project, I find myself using Dispatcher.Invoke a lot. Before each call I test if the current dispatcher is the right one. I want to write a wrapper class like so:

class SafeRunner
{
    //From the thread we always need to run on
    public static System.Windows.Threading.Dispatcher disp;

    public static void Run&lt;T&gt;(Action&lt;T&gt; f, T arg)
    {
        if (disp != System.Windows.Threading.Dispatcher.CurrentDispatcher)
        {
            disp.Invoke(f, arg);
        }
        else
        {
            f(arg);
        }
    }
    public static void Run&lt;T1, T2&gt;(Action&lt;T1,T2&gt; f, T1 arg1, T2 arg2)
    {
        if (disp != System.Windows.Threading.Dispatcher.CurrentDispatcher)
        {
            disp.Invoke(f, arg1, arg2);
        }
        else
        {
            f(arg1, arg2);
        }
    }
    public static void Run&lt;T1, T2, T3&gt;(Action&lt;T1,T2,T3&gt; f, T1 arg1, T2 arg2, T3 arg3)
        {...}
    public static void Run&lt;T1, T2, T3, T4&gt;(Action&lt;T1,T2,T3,T4&gt; f, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
        {...}
}


And I can use it like this:

SafeRunner.Run&lt;string,string&gt;((a,b) =&gt; {
    doSomething(a,b);
    doSomethingElse(a);
    // Maybe a few more lines here
}, "Hello", "World");


This works, but doesn't feel right. Is there a better way?
A couple of things I notice, and they are both around the if statements

I would flip the if statements around so that they are checking the positive test.  I would also put the disp on the right side of the ==.  You can eliminate the else statement, all it really does is clutters up the code.

if (System.Windows.Threading.Dispatcher.CurrentDispatcher == disp)
{
    f(arg);
    return;   
}

disp.Invoke(f, arg);