【问题标题】:Error during UWP app launch in Windows 10 mobile在 Windows 10 移动版中启动 UWP 应用时出错
【发布时间】:2018-05-12 11:03:54
【问题描述】:

我有一个 UWP 应用,在启动期间在开发中心控制台中有很多错误,例如: em_watchdog_timeout_deada444_514cabuxamapache.391043fc20bb3_fa4730peekfge!lockscreenimages.exe_timeout_expired:_event_type_=_targetstatechanged,_timeout_modifier_type_=_none,_server_task_currentstate_=_navigatingto,targetstate=_active。 我怀疑这是由于“App.cs”中的 Cortana 或 Analitycs 激活所致:

private async Task SetupVoiceCommands()
    {
        try
        {
            StorageFile vcdStorageFile = await Package.Current.InstalledLocation.GetFileAsync(@"Commands.xml");
            await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcdStorageFile);
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine("Installing Voice Commands Failed: " + ex.ToString());
        }
    }

private void InitAnalyticsTracker()
    {
        GoogleAnalyticsTracker = AnalyticsManager.Current.CreateTracker("UA-XXXXXXXX");
        AnalyticsManager.Current.ReportUncaughtExceptions = true;
        AnalyticsManager.Current.AutoAppLifetimeMonitoring = true;
        AnalyticsManager.Current.IsDebug = false;
    }

此代码执行于:

protected override async void OnLaunched(LaunchActivatedEventArgs e)
    {
        Frame rootFrame = Window.Current.Content as Frame;

        if (rootFrame == null)
        {
            rootFrame = new Frame();
            rootFrame.NavigationFailed += OnNavigationFailed;

            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                //TODO: Load state from previously suspended application
            }

            Window.Current.Content = rootFrame;
        }

        if (e.PrelaunchActivated == false)
        {
            await SetupVoiceCommands();

            if (rootFrame.Content == null)
            {
                InitAnalyticsTracker();

                rootFrame.Navigate(typeof(Shell), e.Arguments);
            }
            else
            {
                var page = rootFrame.Content as Shell;
                page?.OnLaunchedEvent(e.Arguments);
            }

            Window.Current.Activate();

            CustomizeStatusBar();
        }
    }

很多用户说应用程序甚至没有启动... 请问有什么想法吗?

【问题讨论】:

    标签: c# uwp windows-10-mobile cortana


    【解决方案1】:

    调用await SetupVoiceCommands(); 阻塞了OnLaunched 方法中的其余代码:直到SetupVoiceCommands() 的执行完成,应用程序的主页面才会显示(这应该在短时间内发生)应用程序启动后的一段时间,否则系统将关闭您的应用程序,因为没有响应。

    考虑将await SetupVoiceCommands(); 移近OnLaunched 方法的末尾,例如在CustomizeStatusBar();之后。

    为了更好地了解它如何影响应用程序的执行流程和启动时间,您可以将调用 await SetupVoiceCommands(); 替换为 await Task.Delay(5000); 以模仿延迟,然后尝试在 OnLaunched 周围移动它建议的方法。

    【讨论】:

    • 我今天试试,给你反馈,谢谢你的回答!!
    • @Cabuxa.Mapache 祝你好运!
    • @Cabuxa.Mapache 乐于助人。
    • @a-milto 顺便说一句,如果你想尝试的话,这帮助我解决了 Wal 9000 应用程序中的问题 ;)
    猜你喜欢
    • 2016-01-24
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 2016-08-08
    • 1970-01-01
    • 2016-06-09
    • 2016-02-24
    • 2017-08-08
    相关资源
    最近更新 更多