gpt4 book ai didi

winforms - 尝试读取或写入 protected 内存。这通常表明其他内存已损坏

转载 作者:行者123 更新时间:2023-12-03 22:20:57 26 4
gpt4 key购买 nike

我使用以下方法创建了一个继承自 ComboBox 的 Winforms AutoComplete 组合框控件:

Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
MyBase.OnKeyPress(e)
Dim text As String = Me.Text
If Char.IsLetter(e.KeyChar) Then
text = text + e.KeyChar
End If
If (text.Length = AutoCompleteSearchChars And Char.IsLetter(e.KeyChar)) Then
SetAutoCompleteMethod.Invoke(text)
Me.AutoCompleteSource = AutoCompleteSource.ListItems
Me.Text = text
Me.SelectionStart = text.Length
Me.SelectionLength = 0
If Me.Items.Count > 0 Then
Me.SelectedIndex = 0
End If
e.Handled = True
End If
End Sub

“SetAutoCompleteMethod”是一个委托(delegate),指向填充基于使用组合框中的当前文本作为前缀的组合框项目通配符搜索。这提供了与 ajax 自动完成组合框类似的功能。

第一次调用时一切正常,但第二次调用时出现“尝试读取或写入 protected 内存。这通常表示其他内存已损坏”错误。在更新组合框的所有代码完成后出现错误。我得到以下堆栈跟踪:

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(ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at ApplicationShell.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

有没有人能指出正确的方向来解决这个问题?

最佳答案

当我得到那个错误时,事实证明它确实是取消引用空指针的问题,但它仍然进行了方法调用并且直到它尝试访问其中一个成员变量才崩溃。自从 .Net 出现之前我就没有真正使用过 VB,但是你的堆栈跟踪表明它在某个地方的 native 调用中死了。如果是这种情况,您可能会遇到同样的问题,在这种情况下,我建议您仔细检查这些指针,不仅仅是它崩溃的地方,还有几个级别。

关于winforms - 尝试读取或写入 protected 内存。这通常表明其他内存已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/426499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com