I was trying to implement an aspect following a WPF example, but I can't figure out how to make it work for WinForms.
class RunOnUIThreadAttribute : IMethodInterceptionAspect
{
public override void OnInvoke(MethodInterceptionArgs args)
{
DispatcherObject dispatchedObj = (DispatcherObject)args.Instance;
if (dispatchedObj.CheckAccess())
{
args.Proceed();
}
else
{
dispatchedObj.Dispatcher.Invoke((Action)(() => args.Proceed()));
}
}
}
How do I get the equivalent of Dispatcher
working on Windows Forms?