I want to invoke a general Delegate using async await. I am not working with a prebuilt delegates, but rather the general Delegate class which can receive arguments as an array of objects.
I am doing something like this:
public object InvokeAction(Delegate action, object[] actionArgs = null)
{
if(action == null)
{
return null;
}
return action.DynamicInvoke(args);
}
What I want to do is give an option to run the delegate using await but since DynamicInvoke returns an object, it doesn't have an awaiter.
Is there a way to define a general delegate and make an asynchronous invocation? If not a generic one, is there some version which is close to a generic delegate (It's ok to force the user to some delegate definition) which can be invoked the way I want?