I'm building an app using an existing codebase that is not async-based. I'm wondering if it's practical to reuse this code or if I need to create async versions of the existing codebase. Here is an example:
public abstract class MyAppBase : TickController
{
/// <summary>
/// This method is invoked from a separate thread in the base class
/// </summary>
protected override void OnTick()
{
// Everything in my app is driven from this OnTick loop. I'd like to do async/await "all the way" from here
// by making this code Async and awaitable, however, the method override has a return type of void and
// is not marked with async in the base class. I cannot change this signature, but I can create an async
// version of the baseclass.
Task.Run(() => DoStuffAsync()).ConfigureAwait(false);
base.OnTick();
}
private async Task DoStuffAsync()
{
await Task.Delay(100);
}
}
Is Task.Run() being used correctly here and in good practice? Will exceptions be handled properly?