我希望清理一些代码。我有一个重载的方法。我能不能简化这段代码并在另一个方法中调用一个方法?我不知道怎么做。
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);
}
}