I'd like to add async delegate functions using Task. I want something like :
public delegate Task MethodHook(Object obj);
public MethodHook methodHook;
public async Task Task1(Object obj){
await SomeTask1(obj);
await Task.Delay(600);
}
public async Task Task2(Object obj){
await SomeTask2(obj);
await Task.Delay(600);
}
//...
void Foo(){
methodHook+=Task1;
methodHook+=Task2;
}
public async Task InvokeMethods(Object obj){
await methodHook?.Invoke();
Console.WriteLine("Done!");
}
So when I call InvokeMethods
, SomeTask1 is called, wait until SomeTask1
completion, wait for 600ms, SomeTask2
is called, wait until SomeTask2
completion, wait for 600ms, and finally print "Done!". How can I make this work?
I cannot use methodHook.BeginInvocation(obj,null,null);
for some reason. Is there any solution?