Debugging Windows Store Apps

Windows Store apps can be difficult to debug because they are often started, suspended, and resumed based on user actions. These actions are controlled by the Windows Process Lifetime Management (PLM) environment. When in debug mode, however, these activation events (start, suspend, resume, terminate) are disabled. Fortunately, you can still trigger these events using the debugger.


Note

See Chapter 23, “Developing Windows Store Applications,” for additional details on creating and debugging Windows Store apps.


You debug a PLM event by first setting a breakpoint in the event handler for the event you want to debug. You then start to debug the application. From there you can use the Debug Location toolbar to fire PLM events to respond to app suspend, resume, suspend and shutdown, and even trigger background tasks.

For example, you may want to save the application state when the user navigates away from your app or the device enters a low power state. To do so, you would write code to handle the Suspending event. You might also want to restore your application if the user reopens your application (prior to it being terminated). To do so, you would respond to the Resuming event.

Once you’ve written your event handler, you run the application form the IDE in Debug mode (using the green “play” arrow). You then set a breakpoint inside the given event handler. Finally, you trigger the PLM event by clicking on the Debug Location toolbar and selecting the appropriate event.

Figure 10.60 shows an example; notice the Lifecycle Events option on the Debug Location toolbar. Also, notice the breakpoint set in the event handler, OnSuspending. Clicking the Suspend option from the toolbar will fire from inside the IDE the Suspending event that will trigger the OnSuspending registered handler.

Image

FIGURE 10.60 You can trigger Windows Store PLM events from the debugger.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset