Visual Studio “An unhandled win32 expcetion occured” when clicking button often

梦想的初衷 提交于 2019-12-24 14:58:06

问题


I have a strange issue with my C# UWP-Win10 app. When I re-size the window often or clicking a random button often (>3 times), I'm getting the error:

An unhandled win32 exception occurred in bla.exe [bla-id]

After closing this window the app crashes and in the output-window I get:

The program '[bla-id] bla.exe' has exited with code -1073741811 (0xc000000d).

No more information from Visual Studio. I'm using the serial-port in this app and I've noticed that this error occurs only when I'm connected to the device. But: I've added an empty button (without a Click-handler) and the same error occurs on this button.

Additionally I've looked in the eventviewer and saw the crashed-module:

ntdll.dll (offset 0x00000000000f5670)

How can I trace down the issue? I'm not using external APIs or something else.


回答1:


After a while (two weeks) of testing and debugging I've found the issue: The garbage collector is closing the serialport inputstream and thus the DataReader (which is reading the serialport) dies instantly and throws this unspecified exception. Basically this was an issue with the datareaader not disposing correctly in code. "Mystery" solved.




回答2:


I know this post is three years old, but I found it when I was searching for a solution to this exact same problem, and maybe my experience can help the next person who stumbles upon it.

After reading the OP's response to his own question, I started investigating garbage collection, object disposal, and etc. I found that if my DataReader and DataWriter objects were global in scope, then they were at risk of being garbage collected mid-use. What worked for me was to locally scope those objects every time I needed them, with a using(DataWriter dw = new DataWriter(EventHandlerForDevice.Current.Device.OutputStream)) { ... } block, or similar for the DataReader object. Since implementing them like this, I haven't had any of the win32 exceptions whatsoever. Hope this helps!



来源:https://stackoverflow.com/questions/37059767/visual-studio-an-unhandled-win32-expcetion-occured-when-clicking-button-often

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!