TjD*_*haw 3 c# func task-parallel-library
嘿伙计们,我想清理一些代码.我有重载方法.我可以以某种方式简单地使用这个代码并在另一个方法中调用一个方法吗?无法弄清楚如何做到这一点.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
怎么样:
private Task DecorateWithWaitScreen(Func<Task> action)
=> DecorateWithWaitScreen<int>(async () => { await action(); return 0; });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
743 次 |
| 最近记录: |