【发布时间】:2018-03-10 02:44:21
【问题描述】:
我尝试使用 mvvmlight 作为我的 mvvm 模型,但出现了一些我不明白的错误。它说我不能取消不能使用等待。如果 void 不能使用 await 那么我应该在这里做什么是我的代码:
async void OnLoginButtonClicked(object sender)
{
try
{
var result = await App.AuthenticationClient.AcquireTokenAsync(
Constants.Scopes,
string.Empty,
UiOptions.SelectAccount,
string.Empty,
null,
Constants.Authority,
Constants.SignUpSignInPolicy);
await _navigationservice.NavigateTo(Locator.MainPageViewModel);
}
catch (MsalException ex)
{
if (ex.Message != null && ex.Message.Contains("AADB2C90118"))
{
await OnForgotPassword();
}
if (ex.ErrorCode != "authentication_canceled")
{
// await DisplayAlert("An error has occurred", "Exception message: " + ex.Message, "Dismiss");
}
}
}
错误在await _navigationservice.NavigateTo(Locator.MainPageViewModel);
它在Cannot await 'void' 右侧显示错误消息我应该在这里做什么?
【问题讨论】:
-
将
void更改为Task -
从`_navigationservice.NavigateTo`行中删除
await。该方法无效,因此无法等待。 -
你不能在任何地方等待
void,不仅是在 Xamarin 应用程序中。
标签: c# asynchronous xamarin mvvm mvvm-light