My UWP application crashes in release mode and works fine in debug mode, but I canโt say what the problem is, but I know that this is due to the combination of raising an event from System.Threading.Timer and MVVMLight.
I created a new dummy application and used the same code (ZXing.net.mobile, where I used 2 portable libraries, and I used my own custom control, which is a simplified version of them). I use events instead of <Action> ). This works great, and I'm currently trying to add extra steps to it, i.e. enable mvvmlight and navigation, but so far I canโt reproduce the problem in this dummy application.
The error I am getting is:
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.
The following are:
Unhandled exception at 0x0107D201 (SharedLibrary.dll) in Company.MyApp.App.exe: 0x00001007.
When viewing the Threads window, one of the workflows has the following information, if that helps.
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]
In my UserControl QR code, it uses System.Threading.Timer, and it fires an event when a QR code is detected:
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);
On the page that the UserControl QRCode is hosted on, I have the following code:
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); }); }
As you can see, I pass the QrCode value to my ViewModel, and from there I sent a message and then redirected it to another page:
public void BarcodeFound(string barcodeData) { Messenger.Default.Send<string>(barcodeData, MessengerTokens.QrCodeFound); this.NavigationFacade.NavigateToMyOtherPage(); }
I could go ahead and provide additional code, but as additional breakpoints are added, I see that the code and passing the correct value and going to the right place, but in the end it throws this error. If I add additional error handlers or a dispatcher code, it eventually works and goes to the next page as expected, but when I click on the button in my CommandBar, it takes some time, and in the end it causes the same error, so adding these extra bits of code, I feel like I'm just giving up the problem further down the line.
Does anyone have any suggestions on how I will get around this issue. I'm sorry that I can not share the full application, but definitely can not. Therefore, I know that it will be difficult to provide a solution, but if anyone has suggestions, I will be grateful to them.
As I said, I think the problem is with the combination of streams and mvvmlight, but it makes me wonder if my test application is working as expected, so I'm sure this is not Zxing or my UserControl.
Any help, suggestions would be appreciated or if you need to provide additional information, please tell me that I will try to provide.
Thanks.