I am trying to create an extension method for the generic delegate Action<T> to be able to make simple asynchronous calls on Action<T> methods. It basically just implements the pattern for when you want to execute the method and don’t care about it’s progress:
public static class ActionExtensions
{
public static void AsyncInvoke<T>(this Action<T> action, T param) {
action.BeginInvoke(param, AsyncActionCallback, action);
}
private static void AsyncActionCallback<T>(IAsyncResult asyncResult) {
Action<T> action = (Action<T>)asyncResult.AsyncState;
action.EndInvoke(asyncResult);
}
}
The problem is that it won’t compile because of the extra <T> that makes the AsyncActionCallback generic and have a different signature than expected.
The signature void AsyncActionCallback(IAsyncResult) is expected.
Does anyone know how to work around this or to accomlish what I am trying to do?
1 Answer