System.Windows.Navigation.NavigationService.Navigate throws invalidoperationexception

Frame    Image             Function                                                Offset    
0        coredll.dll       xxx_RaiseException                                      19        
1        mscoree3_7.dll                                                            436488    
2        mscoree3_7.dll                                                            386545    
3        mscoree3_7.dll                                                            540936    
4                          TransitionStub                                          0         
5                          System.Windows.Navigation.NavigationService.Navigate    1652      
6                          XXX.Components.pushScreen        172       
7                          XXX.pushHomeScr                                 996       
8                          XXX.update                                      1488      
9                          .__c__DisplayClass3._ResponseReady_b__0                 700       
10       mscoree3_7.dll                                                            429164    
11       mscoree3_7.dll                                                            185803    
12       mscoree3_7.dll                                                            184423    
13                         System.Reflection.RuntimeMethodInfo.InternalInvoke      112       
14                         System.Reflection.RuntimeMethodInfo.InternalInvoke      1556      
15                         System.Reflection.MethodBase.Invoke                     104       
16                         System.Delegate.DynamicInvokeOne                        476       
17                         System.MulticastDelegate.DynamicInvokeImpl              84        
18                         System.Windows.Threading.DispatcherOperation.Invoke     80        
19                         System.Windows.Threading.Dispatcher.Dispatch            404

I use the following code to enter a new page

Uri navigateUritemp = new Uri(url, UriKind.RelativeOrAbsolute);
if(scrObj.NavigationService.CurrentSource != navigateUritemp)
{
scrObj.NavigationService.Navigate(navigateUritemp);
}

It looks like the following line throws an invalidoperationexception

scrObj.NavigationService.Navigate(navigateUritemp);

can anyone say what is wrong with this code?

+3
source share
3 answers

The general situation in which I saw this InvalidOperationExceptionis that several attempts are made at the same time, or if a navigation attempt occurs when the application is not in the foreground.

This can happen, for example, if the user manages to press the button on the application bar a second time when there is slow navigation.

, - . http://www.nickharris.net/2011/01/windows-phone-7-navigation-is-not-allowed-when-the-task-is-not-in-the-foreground/

+3

if (scrObj.NavigationService.CurrentSource.equals(navigateUritemp)) , . ?

0

:

  • , NavigationService.
  • ( - )
  • 2 XAML (: Page1.xaml, Page2.xaml)
  • - NavigationService MainPage.xaml

    :

    NavigationService.Navigate (new Uri ("/homecreen/Page1.xaml", UriKind.Relative));
    or
    NavigationService.Navigate (new Uri ("/homecreen/Page2.xaml", UriKind.Relative));


if you use UriKind.Relative, be sure to specify the correct path, for example: if you use "homescreen / Page2.xaml", it wants to work, you must first use "/homescreen/Page2.xaml", "/" at the beginning of your path, as root or ~ in ASP.NET

0
source

All Articles