【发布时间】:2015-01-16 01:11:22
【问题描述】:
我有一个 Windows Phone 8.1 通用应用程序,我正在努力为其添加基本的 Cortana 支持。很多关于这方面的文章都是针对 Silverlight 等的。我发现很难找到关于这方面的真正好信息。
到目前为止,如果应用程序已在运行或暂停,我已经激活。但是,如果应用程序完全退出,则在激活后它会立即崩溃。我尝试使用 Hockey 和一个简单的“LittleWatson”例程来捕捉崩溃,但它似乎发生得太快而无法被抓住。我看到了一些关于进行私人测试并尝试获取故障转储的参考,但到目前为止我没有任何运气。
这是我在app.xaml.cs 中的激活码:
protected override void OnActivated(IActivatedEventArgs args) {
base.OnActivated(args);
ReceivedSpeechRecognitionResult = null;
if (args.Kind == ActivationKind.VoiceCommand) {
var commandArgs = args as VoiceCommandActivatedEventArgs;
if (commandArgs != null) {
ReceivedSpeechRecognitionResult = commandArgs.Result;
var rootFrame = Window.Current.Content as Frame;
if (rootFrame != null) {
rootFrame.Navigate(typeof(CheckCredentials), null);
}
}
}
}
这是我对命令结果的检查:
private async Task CheckForVoiceCommands() {
await Task.Delay(1); // not sure why I need this
var speechRecognitionResult = ((App)Application.Current).ReceivedSpeechRecognitionResult;
if (speechRecognitionResult == null) {
return;
}
var voiceCommandName = speechRecognitionResult.RulePath[0];
switch (voiceCommandName) {
// omitted
}
((App)Application.Current).ReceivedSpeechRecognitionResult = null;
}
通过插入消息等,我很确定它在到达这一步之前很久就失败了。
我可能缺少一些简单的东西,但我不知道是什么......
是什么导致了这么早的崩溃?
编辑 我尝试过的一件事是使用“调试而不启动”配置来尝试捕获异常。当我这样做时,该应用程序似乎永远挂在启动屏幕上的调试器中。然而,这确实让我强行休息。它挂在了
global::Windows.UI.Xaml.Application.Start((p) => new App());
据我所知,这只是告诉我应用程序挂在某个地方。这是调用堆栈中唯一的一行。
【问题讨论】:
-
您是否尝试过存储语音命令名称而不是原始的SpeechRecognitionResult 对象?我注意到它是一个编组资源,我怀疑这会在将其存储在内存中时导致访问异常。
-
@lthibodeaux 谢谢你的建议!我将代码更改为仅传递命令文本字符串而没有更改。
标签: c# windows-phone-8.1 win-universal-app cortana