询问者
C# 关于Winfrom 程序中出现 System.AccessViolationException 的求助

问题
-
发生了 System.AccessViolationException
HResult=-2147467261
Message=尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
Source=System.Windows.Forms
StackTrace:
在 System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
在 System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
在 System.Windows.Forms.Control.DefWndProc(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.TextBoxBase.WndProc(Message& m)
在 System.Windows.Forms.RichTextBox.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, Int32& wParam, Int32& lParam)
在 System.Windows.Forms.TextBoxBase.GetSelectionStartAndLength(Int32& start, Int32& length)
在 System.Windows.Forms.TextBoxBase.AppendText(String text)
全部回复
-
当前使用方法,使用环境卫生 WIN10&VS2012
private void Port1ShowMSG(string strMessage)
{
try
{
{
if (strMessage != "")
{
strMessage += "\r\n";
}
if (grp1_RchShow.InvokeRequired)
{
grp1_RchShow.Invoke(new EventHandler(delegate
{
if (strMessage != null)
{
SystemError.SystemLog(m_strPortName[0], strMessage);
grp1_RchShow.AppendText(strMessage);
//grp1_RchShow.Select(grp1_RchShow.Text.Length, 0);
//grp1_RchShow.ScrollToCaret();
}
}));
}
else
{
SystemError.SystemLog(m_strPortName[0], strMessage);
grp1_RchShow.AppendText(strMessage);
//grp1_RchShow.Select(grp1_RchShow.Text.Length, 0);
//grp1_RchShow.ScrollToCaret();
}
}
}
catch(Exception ex)
{
SystemError.SystemLog(m_strPortName[0], ex.Message);
}
}还请各位大侠帮忙瞅瞅
-
Hi,
我这里找到了一个相关链接或许你可以参考一下,里面提出了多种可能的情况。
Regards,
Kyle
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.