界面卡住不动,NavigationService.Navigate 不转向下一个页面
public static async void SavingDataThread()
{
//在当前页面进行相关进度操作
string struid = null;
int persent = 0;
int TotalCount = App.Global.AllCons.Count;
ContactStore store1 = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);
//serach
IReadOnlyDictionary<string, StoredContact> conlistWP = await SaveData.QueryDuplicateContacts(store1);
for ( int i = 0; i < TotalCount;i++)
{
struid = SaveData.IsExistContact(conlistWP, App.Global.AllCons[i]);
if (struid != null)
{
App.GlobalContactinfo.GlobalDuplicateContacts.Add(App.Global.AllCons[i]);
await SaveData.Info(struid, store1, App.Global.AllCons[i]);
}
else
{
await SaveData.AddContacts(store1, App.Global.AllCons[i]);
App.Global.AddCount++;
}
persent = (int)((float)(i + 1) * 100 / (float)TotalCount);
_mainPage.Dispatcher.BeginInvoke(delegate()
{
_mainPage.mainProgressbar.Value = persent;
});
}
await Task.Run(() =>
{
if (persent >= 100)
return;
});
//转向下一个页面
this.Dispatcher.BeginInvoke(delegate()
{
if (App.GlobalContactinfo.GlobalDuplicateContacts.Count == 0)
{
NavigationService.Navigate(new Uri("/ResultPage.xaml", UriKind.Relative));
}
else
{
NavigationService.Navigate(new Uri("/DetailPage.xaml", UriKind.Relative));
}
});
}
this.Dispatcher.BeginInvoke(delegate()
{
if (App.GlobalContactinfo.GlobalDuplicateContacts.Count == 0)
{
//程序可以走到这里
System.Windows.MessageBox.Show("0");
NavigationService.Navigate(new Uri("/ResultPage.xaml", UriKind.Relative));
}
else
{
//程序可以执行到这里
System.Windows.MessageBox.Show("else");
NavigationService.Navigate(new Uri("/DetailPage.xaml", UriKind.Relative));
}
});
});
}
if (persent >= 100){
return;
}
//转向下一个页面
this.Dispatcher.BeginInvoke(delegate()
{
if (App.GlobalContactinfo.GlobalDuplicateContacts.Count == 0)
{
NavigationService.Navigate(new Uri("/ResultPage.xaml", UriKind.Relative));
}
else
{
NavigationService.Navigate(new Uri("/DetailPage.xaml", UriKind.Relative));
}
});