我的UWP应用程序在发布模式下崩溃,并且在调试模式下正常工作,但我无法指出问题是什么,但我知道它与从System.Threading.Timer和MVVMLight引发事件的组合。UWP Windows 10应用程序在发布模式下崩溃,但在调试模式下正常工作
我创建了一个新的虚拟应用程序并使用相同的代码(ZXing.net.mobile,我使用了2个便携式库,并使用了我自己的用户控件,这是他们的简化版本 - 我使用事件代替<Action>
)。这工作正常,我目前正试图把更多的步骤,即包括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码用户控件,它使用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);
在页面承载QR码用户控件,我“已经得到了下面的代码:
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);
});
}
正如你所看到的,我的QR码值传递给我的视图模型,并从那里,我发了消息,然后重新定向到另一个页面:
public void BarcodeFound(string barcodeData)
{
Messenger.Default.Send<string>(barcodeData, MessengerTokens.QrCodeFound);
this.NavigationFacade.NavigateToMyOtherPage();
}
我可以继续前进并提供额外的代码,但是当我添加额外的断点时,我可以看到代码并传递正确的值并转到正确的位置,但最终引发此错误。如果我添加额外的错误处理程序或调度程序代码,它最终会按预期工作并进入下一页,但是当我点击CommandBar中的按钮时,它需要一段时间,最终会抛出相同的错误,因此通过添加这些附加代码中的一小部分,我觉得我只是将问题推到了最后。
任何人都有如何解决这个问题的任何建议。我希望我可以分享完整的应用程序,但肯定不能。所以我知道这将很难提供解决方案,但如果有人有建议,我会很感激他们。
正如我所说的,我认为这个问题是由线程和mvvmlight的结合导致的,但它让我坚信我的测试应用程序到目前为止完全按照预期工作,所以我非常肯定这不是Zxing或我的用户控件。
任何帮助,建议将不胜感激,或者如果你需要我提供额外的信息,请让我知道什么,我会尽量提供它。
谢谢。
这可能是一个与.NET Native编译代码相关的问题吗?您是否尝试过使用“编译.NET本地工具链”进行调试? – Plac3Hold3r
嗨,我已经试过了,我也尝试过与'优化代码'选中,并仍然不会在调试模式下崩溃。 – Thierry