Skip to content

Instantly share code, notes, and snippets.

@meklarian
Created July 5, 2010 15:22
Show Gist options
  • Save meklarian/464458 to your computer and use it in GitHub Desktop.
Save meklarian/464458 to your computer and use it in GitHub Desktop.
Extension Method Class to patch a function and return a lambda that reroutes through a WPF/Silverlight Dispatcher
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace YourFavoriteNamespace
{
public static class Dispatch
{
public static Action<T> Route<T>(this Dispatcher disp, Action<T> Original)
{
return ((a) =>
{
disp.BeginInvoke(Original, new object[] { a });
});
}
public static Action<T1, T2> Route<T1, T2>(this Dispatcher disp, Action<T1, T2> Original)
{
return ((a, b) =>
{
disp.BeginInvoke(Original, new object[] { a, b });
});
}
public static Action<T1, T2, T3> Route<T1, T2, T3>(this Dispatcher disp, Action<T1, T2, T3> Original)
{
return ((a, b, c) =>
{
disp.BeginInvoke(Original, new object[] { a, b, c});
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment