AutoComplete Texbox error - write to protected memory(自动完成 Texbox 错误 - 写入受保护的内存)
问题描述
我有一个查看数据库的自动完成文本框.有时我在打字时收到以下错误.
I have an autocompleate textbox that looks into a data base. Some times while I'm typing I received the following error.
试图读取或写入受保护的内存.这通常表明其他内存已损坏.
这里是代码
private void tBSearchName_TextChanged(object sender, EventArgs e)
{
try
{
//test length
if (tBSearchName.Text.Length > 3)
{
//prevent db lookups
if (!tBSearchName.Text.ToLower().Contains(oldName) || oldName == String.Empty)
{
//test for a name + first letter of last name
if (Regex.IsMatch(tBSearchName.Text, @"(w)+s(w)+(.)*"))
{
tBSearchName.AutoCompleteCustomSource = AccessDB.serachByNemberName(tBSearchName.Text);
tBSearchName.AutoCompleteMode = AutoCompleteMode.Suggest;
//prevent db lookups
oldName = tBSearchName.Text.ToLower();
}
}
}
}
catch
{
}
}
我的见解是,我应该在搜索完成时快速输入应用程序,有人可以建议如何做到这一点.或对正在发生的事情的任何其他见解
My insight is that I should frezz typing into the application while search is done, can some suggest how to do this. Or any other insight on what is happening
推荐答案
这是 Windows Forms 的一个 bug自动完成 API 的包装器.Windows 窗体不保护 AutoCompleteCustomSource 对象在被自动完成创建的后台线程枚举时被替换.
It is a bug in Windows Forms's wrapper of autocomplete APIs. Windows Forms does not protect the AutoCompleteCustomSource object from being replaced while it is being enumerated by a background thread created by autocomplete.
您可以尝试替换自动补全对象或使用 IAutoCompleteDropDown 接口重置枚举器.
这篇关于自动完成 Texbox 错误 - 写入受保护的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:自动完成 Texbox 错误 - 写入受保护的内存


- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 使用 rss + c# 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01