在 Windows 10 移动设备中启动 UWP 应用程序时出错
Error during UWP app launch in Windows 10 mobile
我有一个 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();
}
}
很多用户说应用程序甚至没有启动...
有什么想法吗?
调用 await SetupVoiceCommands();
阻塞了 OnLaunched
方法中的其余代码:在 SetupVoiceCommands()
执行完成之前,应用程序的主页不会显示(这应该在应用程序启动后的短时间内发生,否则系统将关闭您的应用程序没有响应)。
考虑将 await SetupVoiceCommands();
移动到更接近 OnLaunched
方法的末尾,例如在 CustomizeStatusBar();
.
之后
为了更好地了解它如何影响应用程序的执行流程和启动时间,您可以将调用 await SetupVoiceCommands();
替换为 await Task.Delay(5000);
以模仿延迟,然后尝试移动它按照建议围绕 OnLaunched
方法。
我有一个 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();
}
}
很多用户说应用程序甚至没有启动... 有什么想法吗?
调用 await SetupVoiceCommands();
阻塞了 OnLaunched
方法中的其余代码:在 SetupVoiceCommands()
执行完成之前,应用程序的主页不会显示(这应该在应用程序启动后的短时间内发生,否则系统将关闭您的应用程序没有响应)。
考虑将 await SetupVoiceCommands();
移动到更接近 OnLaunched
方法的末尾,例如在 CustomizeStatusBar();
.
为了更好地了解它如何影响应用程序的执行流程和启动时间,您可以将调用 await SetupVoiceCommands();
替换为 await Task.Delay(5000);
以模仿延迟,然后尝试移动它按照建议围绕 OnLaunched
方法。