自动完成 Texbox 错误 - 写入受保护的内存 [英] AutoComplete Texbox error - write to protected memory

查看:20
本文介绍了自动完成 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 错误 - 写入受保护的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆