Develop a multi-page Windows Phone 7 ApplicationProgramIn the process of page navigation, some potential "secrets" related to page navigation are occasionally discovered ".
In my application, the Program on page a responds to the Click Event of a button and uses the navigationservice. navigate () method to jump to another page B. In the onnavigatedto event on page B, some judgment will be made based on the needs of the business logic. Then, when some business data does not meet the conditions, a message dialog box will pop up (MessageBox is used. show () method ). This operation process does not seem to be a problem. However, after careful testing, it is found that after the message dialog box is displayed, if the user does not perform any operation, the entire application will be forcibly closed in about 10 seconds.
This phenomenon cannot be reproduced during online debugging. It can only be directly run through the Application List!
After repeated experiments and speculation, I think that the operation of "forcibly disabling Applications" should be handled by the operating system. Think about it again, it is quite logical. We can try to set a breakpoint at the onnavigatedto event function entrance on page B, and then trigger the page Jump in the online debug environment. As you can see, when this event is triggered, page A is still displayed on the mobile phone screen, indicating that the page navigation is not over and is in progress. At this time, the MessageBox dialog box pops up, which hinders the smooth jump of the page and puts it in the "stuck" status (The MessageBox. Show () method stops the Program Stream where the statement is called, and continues after the user responds to the message dialog box.). According to the Development Guide of Windows Phone 7, if the page is stuck for up to 10 seconds, kill it. This explains why in the preceding example, the application is forcibly closed when the user does not respond within 10 seconds.
From this point of view, we can hardly guess that if we try to execute some "heavyweight" operations in the onnavigatedto event, when the process stops for more than 10 seconds, it will also be forcibly shut down by the system.
The following figure describes the content of this article:
If you need to execute the necessary processing logic and pop up MessageBox when you just jump to page B, you can consider using the loaded event of page B. The trigger time of this event is later than the onnavigatedto event, but the entire page navigation has been completed, and page A has completely exited the mobile phone screen. Therefore, it is safer to bring up the MessageBox In the loaded event. However, it is worth noting that the loaded event is triggered only once when you enter this page, while the onnavigatedto event is triggered every time the page is displayed (for example: when you press start or search in the status of page B, and then press back to return to page B ).
If you are interested, you can download the example.CodeTo measure the test:
Download Code
I hope this article will serve as a reminder to those who develop Windows Phone 7 multi-page applications.