Hello all!

Sometimes, not consistently, focus change cause the WinForm
application, running in debug mode, to throw following exception:
==================================================
"System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt.
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.ToolTip.WndProc(Message& msg)
at System.Windows.Forms.ToolTip.ToolTipNativeWindow.WndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at MqPlus.Gui.FrmMain.Main() in
C:\Projects\MqPlus\MqPlus\FrmMain.cs:line 352"
==================================================

The scenario is: run application (F5), switch to other application
(Alt+Tab), switch vice versa
to application.
There is no unsafe code in application. There is no COM/COM+/or other
not .NET libraries usage.

Do someone have idea what may cause such exception?

Thanks ahead

Re: System.AccessViolationException running debugger by keremskusmezer

keremskusmezer
Mon Sep 25 05:13:38 CDT 2006

Can you provide more of the source code for review? For Example the
portion of the application.run???
Are you doing some multithreaded operation there???
V&G wrote:
> Hello all!e
>
> Sometimes, not consistently, focus change cause the WinForm
> application, running in debug mode, to throw following exception:
> ==================================================
> "System.AccessViolationException: Attempted to read or write protected
> memory. This is often an indication that other memory is corrupt.
> 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.ToolTip.WndProc(Message& msg)
> at System.Windows.Forms.ToolTip.ToolTipNativeWindow.WndProc(Message&
> m)
> at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
> Int32 msg, IntPtr wparam, IntPtr lparam)
> at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
> msg)
> at
> System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
> dwComponentID, Int32 reason, Int32 pvLoopData)
> at
> System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
> reason, ApplicationContext context)
> at
> System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
> reason, ApplicationContext context)
> at System.Windows.Forms.Application.Run(Form mainForm)
> at MqPlus.Gui.FrmMain.Main() in
> C:\Projects\MqPlus\MqPlus\FrmMain.cs:line 352"
> ==================================================
>
> The scenario is: run application (F5), switch to other application
> (Alt+Tab), switch vice versa
> to application.
> There is no unsafe code in application. There is no COM/COM+/or other
> not .NET libraries usage.
>
> Do someone have idea what may cause such exception?
>
> Thanks ahead