1
在Windows 7上使用Windows窗體在Visual Studio 2017中獲取以下錯誤。這種情況發生在多臺計算機上。我在標籤中有一組編輯框,當在組合框中選擇一個「表單」時,它們都被設置爲隱藏或可見。我會將文本導入到這些編輯框中,滾動滾動或通過組合框的上/下箭頭選擇要顯示或隱藏的不同標籤,最終這些窗體中的編輯框會變爲空白。當你去輸入編輯框時,你會得到內存錯誤。我搜索並搜索了一個沒有運氣的解決方案。任何幫助將非常感激。C#保護內存錯誤,緩慢地殺死我的大腦
System.AccessViolationException occurred
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=System.Windows.Forms
StackTrace:
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.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.TextBox.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.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 (IntPtr 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 Notes.Program.Main() in documents\visual studio 2017\Projects\Notes\Notes\Program.cs:line 19
用於導入編輯框的代碼變爲空白。
List<string> ort = imp.Split(new[] { Environment.NewLine }, StringSplitOptions.None).ToList();
//Name regex match
var match = new Regex(@"((?<=:).*(?=\[))");
var name = match.Match(ort[0]);
if (tChoice == 0) { user.Text = String.Empty; user.AppendText(name.Groups[0].ToString()); }
if (tChoice == 1) { pwuser.Text = String.Empty; pwuser.AppendText(name.Groups[0].ToString()); }
if (tChoice == 2)
{
gmmuser.Text = String.Empty; requser.Text = String.Empty; reqAuser.Text = String.Empty; billuser.Text = String.Empty;
gmmuser.AppendText(name.Groups[0].ToString()); requser.AppendText(name.Groups[0].ToString()); reqAuser.AppendText(name.Groups[0].ToString()); billuser.AppendText(name.Groups[0].ToString());
}
if (tChoice == 3) { emailuser.Text = String.Empty; emailuser.AppendText(name.Groups[0].ToString()); }
我們可以看到一些代碼嗎?你能提供一個再現問題的最簡單的例子嗎?我們也從查看鼠標滾輪和查看事件處理程序開始。 – khargoosh
就處理程序而言,我沒有使用鼠標滾輪進行任何設置。我甚至不知道代碼的哪一部分導致了這一點。這似乎是一個普遍的錯誤,我不知道在哪裏查明確切原因。 – DasGoat
你在做任何p/invoke調用嗎?開始從應用程序中刪除東西,直到問題消失。那麼你至少縮小了它的範圍。然後...向我們展示代碼。 – khargoosh