I want to cleanup some of my code. I have overloaded method. Can I somehow simplyfy this code and invoke one method in another ? Cant figure out how to do this.
private async Task<T> DecorateWithWaitScreen<T>(Func<Task<T>> action)
{
SplashScreenManager.ShowForm(this, typeof(WaitForm), true, true, false);
try
{
return await action();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
throw;
}
finally
{
SplashScreenManager.CloseForm(false);
}
}
private async Task DecorateWithWaitScreen(Func<Task> action)
{
SplashScreenManager.ShowForm(this, typeof(WaitForm), true, true, false);
try
{
await action();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
throw;
}
finally
{
SplashScreenManager.CloseForm(false);
}
}
How about:
private Task DecorateWithWaitScreen(Func<Task> action)
=> DecorateWithWaitScreen<int>(async () => { await action(); return 0; });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With