一些背後的故事:的Windows窗體ComboBox造成間歇System.AccessViolationException
我尋覓既計算器和谷歌要弄清楚這個特定的異常原因。
我們有一個Windows Forms(C#,.NET 2.0)應用程序偶爾會拋出System.AccessViolationException(下面的堆棧跟蹤)。在Windows XP(SP3)和Windows Vista(SP2)上都發生異常。從用戶輸入中,我們已經確定當ComboBox的選定索引更改時發生異常。
ComboBox是一個標準的Windows窗體組件,它包含在繼承System.Windows.Forms.UserControl
的自定義控件中。
我的主要查詢是:
如果這個異常是從哪裏來的?
- 它是從.NET框架中的一些內部錯誤?
- 它可能是在
SelectedIndexChanged
事件中分派的代碼嗎?在計算器
相關主題:
- finding the cause of System.AccessViolationException - 提到這個異常相當於未處理的異常,只知道它是由.NET運行庫而不是OS抓獲。
- Can a System.AccessViolationException happen because of faulty RAM? - 將存在故障的RAM視爲罪魁禍首。不過可能的是,我不覺得它很合理,因爲它最近發生在許多不同的機器上。它們全部具有錯誤RAM的概率很低。
堆棧跟蹤:
Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Type: System.AccessViolationException
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
感謝您的回覆@rewinder。實際上,第二個鏈接可能很有趣。然而,應用修補程序/服務包是我們儘可能避免的,將應用程序安裝在數百臺機器上。我目前正在調查組合框是否被改變,同時GUI線程對它做了一些工作 - 一個傳言說組合框的底層實現不完全是線程安全的。 – Christoffer 2011-05-31 13:15:51
@Christoffer:好的。那麼,讓我知道你是否找到任何東西。 – 2011-05-31 13:20:22
在Microsoft支持部門發現另一個有點相關的主題:http://support.microsoft.com/kb/952544但我沒有使用任何自動完成功能。但是,可以將項目添加到Items集合OnKeyDown或OnSelectedIndexChanged。我不知道這是否會導致問題,我會繼續調查。 – Christoffer 2011-06-01 08:54:56