【发布时间】:2016-04-23 20:38:10
【问题描述】:
我的 UWP 应用在发布模式下崩溃,在调试模式下工作正常,但我无法确定问题所在,但我知道这与从 System.Threading.Timer 和 MVVMLight 引发事件的组合有关.
我创建了一个新的虚拟应用程序并使用相同的代码(ZXing.net.mobile,我使用了 2 个可移植库,并使用了我自己的用户控件,这是他们的简化版本 - 我使用事件而不是 @987654321 @)。这很好用,我目前正在尝试添加更多步骤,即包括 mvvmlight 和导航,但到目前为止,我无法在这个虚拟应用程序中重现问题。
我得到的错误是:
Unhandled exception at 0x58C1AF0B (mrt100_app.dll) in Company.MyApp.App.exe:
0xC0000602: A fail fast exception occurred. Exception handlers will not be
invoked and the process will be terminated immediately.
接着是:
Unhandled exception at 0x0107D201 (SharedLibrary.dll) in
Company.MyApp.App.exe: 0x00001007.
查看“线程”窗口时,如果有帮助,其中一个工作线程具有以下信息。
Not Flagged > 4012 0 Worker Thread <No Name>
System.Private.Interop.dll!System.Runtime.InteropServices.
ExceptionHelpers.ReportUnhandledError Normal
[External Code]
System.Private.Interop.dll!System.Runtime.InteropServices.ExceptionHelpers.
ReportUnhandledError(System.Exception e) Line 885
System.Private.Interop.dll!Internal.Interop.InteropCallbacks.ReportUnhandledError
(System.Exception ex) Line 17
System.Private.WinRTInterop.CoreLib.dll!Internal.WinRT.Interop.WinRTCallbacks.
ReportUnhandledError(System.Exception ex) Line 274
System.Private.CoreLib.dll!System.RuntimeExceptionHelpers.ReportUnhandledException
(System.Exception exception) Line 152
System.Private.Threading.dll!System.Threading.Tasks.AwaitTaskContinuation.
ThrowAsyncIfNecessary(System.Exception exc) Line 784
System.Private.Threading.dll!System.Threading.WinRTSynchronizationContext.Invoker.
InvokeCore() Line 182
System.Private.Threading.dll!System.Threading.WinRTSynchronizationContext.Invoker.
Invoke(object thisObj) Line 162
System.Private.CoreLib.dll!System.Action<System.__Canon>.
InvokeOpenStaticThunk(System.__Canon obj)
System.Private.WinRTInterop.CoreLib.dll!Internal.WinRT.Interop.WinRTCallbacks.PostToCoreDispatcher.AnonymousMethod__0() Line 266
MyCompany.MyApp.App.exe
MyCompany.MyApp.App.ViewModels.ValidateHandler.Invoke(string pin)
MyCompany.MyApp.App.McgInterop.dll!McgInterop.ReverseComSharedStubs
.Proc_(object __this, System.IntPtr __methodPtr) Line 6163
MyCompany.MyApp.App.McgInterop.dll!Windows.UI.Core.DispatchedHandler__Impl.Vtbl.Invoke__STUB(System.IntPtr pComThis) Line 45147
[External Code]
在我的 QR 码 UserControl 中,它使用 System.Threading.Timer 并在找到 QR 码时引发事件:
timerPreview = new Timer(async (state) =>
{
....
// Check if a result was found
if (result != null && !string.IsNullOrEmpty(result.Text))
{
Debug.WriteLine("Barcode Found: " + result.Text);
if (!this.ContinuousScanning)
{
delay = Timeout.Infinite;
await StopScanningAsync();
}
else
{
delay = this.ScanningOptions.DelayBetweenContinuousScans;
}
OnBarcodeFound(result.Text);
}
timerPreview.Change(delay, Timeout.Infinite);
}, null,
this.ScanningOptions.InitialDelayBeforeAnalyzingFrames,
Timeout.Infinite);
在托管 QRCode 用户控件的页面中,我有以下代码:
private async void ScannerControl_BarcodeFound(string barcodeValue)
{
var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
Debug.WriteLine(barcodeValue);
GetViewModel.BarcodeFound(barcodeValue);
});
}
如您所见,我将 QrCode 值传递给我的 ViewModel,然后我从那里发送了一条消息,然后重定向到另一个页面:
public void BarcodeFound(string barcodeData)
{
Messenger.Default.Send<string>(barcodeData, MessengerTokens.QrCodeFound);
this.NavigationFacade.NavigateToMyOtherPage();
}
我可以继续提供额外的代码,但是当我添加额外的断点时,我可以看到代码并传递了正确的值并转到了正确的位置,但最终它会抛出这个错误。如果我添加额外的错误处理程序或调度程序代码,它最终会正常工作并按预期进入下一页但是当我单击 CommandBar 中的按钮时,它需要一段时间并且最终会引发相同的错误,因此通过添加这些额外的一些代码,我觉得我只是把问题往下推。
任何人都对我如何解决这个问题有任何建议。我希望我可以分享完整的应用程序,但绝对不能。所以我知道很难提供解决方案,但如果有人有建议,我将不胜感激。
正如我所说,我认为问题是线程和 mvvmlight 组合的结果,但我的测试应用程序到目前为止完全按预期工作,这让我抓狂,所以我很确定它不是 Zxing 或我的 UserControl .
任何帮助、建议将不胜感激,或者如果您需要我提供其他信息,请告诉我什么,我会尽力提供。
谢谢。
【问题讨论】:
-
这可能是与 .NET Native 编译代码相关的问题吗?您是否尝试过启用“使用 .NET Native 工具链编译”进行调试?
-
嗨,我已经尝试过了,我也尝试过选择“优化代码”,但在调试模式下仍然不会崩溃。
标签: win-universal-app mvvm-light zxing dispatcher