我有以下Task想要await
public Task ShowWindow<TWindow>(TWindow window) where TWindow : Window
{
var task = new TaskCompletionSource<bool>();
window.Owner = Application.Current.MainWindow;
window.ShowDialog();
task.SetResult(window.DialogResult ?? false);
window.Focus();
return task.Task;
}
当我称它为完美时:
private async void SettingsButton_Click(object sender, RoutedEventArgs e)
{
await ShowWindow(new SettingsWindow());
// more code
}
我如何获得的结果Task? 我想象过类似以下的内容,但是显然我错过了一些东西:
private async void SettingsButton_Click(object sender, RoutedEventArgs e)
{
bool result = await ShowWindow(new SettingsWindow());
if(result == true)
doSomething();
}
这给了我一个错误:Await task returns no value 但是我给我的印象是我要退货。
慕斯王
相关分类