深入了解Windows应用程序生命周期管理与开发流程
1. 激活事件管理
为了遵循逻辑流程,我们需要开始管理激活事件。首先在Visual Studio 2013中创建一个新项目,在你喜欢的编程语言部分,选择空白应用模板来创建一个新的Windows应用。创建项目后,在App.xaml.cs文件中可以看到OnLaunched方法的默认实现。这个文件代表应用程序的主类,继承自Application类,该类公开了代表应用程序在操作系统中行为的方法、事件和属性。
OnLaunched方法会在用户显式执行应用程序时调用,而OnActivated方法会在应用程序因其他情况启动时调用,例如响应合约订阅。
1.1 C#实现
在C#中,OnLaunched方法如下:
protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG // Show graphics profiling information while debugging. if (System.Diagnostics.Debugger.IsAttached) { // Display the current frame rate counters this.DebugSettin