Ok, so, I'm almost there and need just a small bit of advise to get over this hump! So, the reason i asked this questoin Async delegate - What is proper syntax? is because I'm trying to call a delegate function asynchronously (using await ...).
So, here I have a class which uses a library which accepts a delegate. The library calls the delegate when triggered. It looks something like this.
Example.Question.Base{
public static class Consumer{
private delegate bool Redo();
private static Redo callbackFunction;
public static async Task<T> Go(){
// Do some stuff ...
// now I want to set up my delegate so this library
// I'm using can call back my delgate function when
// an event occurs that it manages
callbackFunction = NonAsync;
SomeLibrary someLibrary = new SomeLibary();
await someLibrary.SomeMethod(callbackFunction);
}
public static bool NonAsync()
{
// Do some work ...
return false;
}
}
// so now the callbackFunction is called from
// the libary when some event occurs. So that
// means the actual method "NonAsync()" is called!
}
The logic in the library that calls back this delgate looks like this
Example.Question.Library{
public ...{
public ... SomeMethod(Delegate func){
func.DynamicInvoke();
}
}
}
this works just fine. What I need is to be able to call the Delegate from the library asynchronously.
need some help getting there
So i want something that looks like this...
...from the library which calls the delegate...
public ... SomeMethod(Delegate func){
await func.DynamicInvoke();
}
... from the consumer of the library which defines the delegate ...
Example.Question.Base{
public static class Consumer{
// ...
public static async Task<T> Go(){
// ...
callbackFunction = await Async;
// ...
}
public static async Task<bool> Async()
{
// Do some work ...
return await Task.FromResult<bool>(false);
}
}
}
But the issue is I get a compiler error saying "Cannot await 'method group'"