Win8开发笔记2 OnLaunched介绍

时间:2022-12-28 23:12:07

Class App 中 OnLaunched(LaunchActiatedEventArgs args) 是在应用程序正常启动时调用,一般包括两种情况:初次启动、挂起后继续,其中参数args指的是上一次的软件上一次运行的状态,可以通过下面的代码来测试:

 

            /*------------------------------------------------------------------------------------*/
            // 判断前一个状态   ***注意是前一个状态
            string State = string.Empty;
            switch (args.PreviousExecutionState)
            {
                case ApplicationExecutionState.ClosedByUser:
                    State = string.Format("yao---{0} - 应用程序被用户关闭。", DateTime.Now.ToString("HH:mm:ss"));
                    break;
                case ApplicationExecutionState.NotRunning:
                    State = string.Format("yao---{0} - 应用程序未运行。", DateTime.Now.ToString("HH:mm:ss"));
                    break;
                case ApplicationExecutionState.Running:
                    State = string.Format("yao---{0} - 应用程序正在运行。", DateTime.Now.ToString("HH:mm:ss"));
                    break;
                case ApplicationExecutionState.Suspended:
                    State = string.Format("yao---{0} - 应用程序被挂起。", DateTime.Now.ToString("HH:mm:ss"));
                    break;
                case ApplicationExecutionState.Terminated:
                    State = string.Format("yao---{0} - 应用程序终止运行。", DateTime.Now.ToString("HH:mm:ss"));
                    break;
                default:
                    State = "";
                    break;
            }
            System.Diagnostics.Debug.WriteLine(State);
            /*------------------------------------------------------------------------------------*/  

 

另外推荐一个系统学习Win8开发贴:

http://bbs.windevcenter.com/forum.php?mod=viewthread&tid=2869&reltid=2868&pre_thread_id=3721&pre_pos=4&ext=