I am not sure how to handle a following scenario. There is an interface that defines an event handling method 'OnSomethinHappening()'.
There is a base class that implements this as a virtual method and uses some async code in it.
There is a derived class that wants to override the virtual method, but also call the base.OnSomethingHappening().
public interface ISomething
{
void OnSomethingHappening();
}
public class BaseClass
{
public virtual async void OnSomethingHappening()
{
await Task.Delay(1999);
}
}
public class DerivedClass : BaseClass
{
public override void OnSomethingHappening()
{
base.OnSomethingHappening();
//some more code
}
}
The problem is, I cannot mark the method invocation as awaitable, since it returns void. It is fine to have async void methods for event handlers, so it cannot be changed to a Task (it ain't my code either).
So, how should I make sure that my derived class executes the base.OnSomethingHappening() properly before going to own code?
Does this solution make sense in the derived class?:
public override async void OnSomethingHappening()
{
await Task.Run(()=> base.OnSomethingHappening());
//some more code
}