C# Xamarin页面导航在任务继续中不起作用
导航对象通过构造函数注入C# Xamarin页面导航在任务继续中不起作用,c#,xamarin,async-await,task,C#,Xamarin,Async Await,Task,导航对象通过构造函数注入 public class CreateAccountViewModel : BaseViewModel { private INavigation navigation; public CreateAccountViewModel(INavigation navigation) { this.navigation = navigation; } 导航在ContinueWith中不起作用,我只想在CreateUserAs
public class CreateAccountViewModel : BaseViewModel
{
private INavigation navigation;
public CreateAccountViewModel(INavigation navigation)
{
this.navigation = navigation;
}
导航在ContinueWith中不起作用,我只想在CreateUserAsync完成后导航到MyPage()。我该怎么做呢。提前谢谢。你有例外吗?@StephenCleary:没有,我没有例外。在调试过程中,我还了解到MyPage()对象已成功创建并返回。为什么在第一次
wait
之后使用ContinueWith
而不是内联执行代码?我怀疑PopModalAsync
是否在PushModalAsync
之前运行,因为嵌套异步。。
protected async Task ExecuteCreateAccountCommand()
{
if (validateDetails())
{
try
{
IsLoading = true;
await SvcHelper.SvcHelper.CreateUserAsync(new Services.Models.LoginInfo
{
LoginId = Email,
LoginPassword = Password,
UserId = 0,
UserHandle = Cellno
}).ContinueWith(x =>
{
IsLoading = false;
(Forms.Context as Activity).RunOnUiThread(async () =>
{
await navigation.PushModalAsync(new MyPage());
}
);
});
}
catch (Exception exc)
{
System.Diagnostics.Debug.WriteLine("###Error### : " + exc.Message + exc.StackTrace);
}
}
else
{
// details not valid
//await DisplayAlert ("Alert", "Email Address not valid", "OK");
return;
}
await navigation.PopModalAsync();
}
}