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

查看:63
本文介绍了自动完成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窗体的错误自动完成API的包装器.当自动完成创建的后台线程枚举AutoCompleteCustomSource对象时,Windows窗体不会保护它不会被替换.

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.

您可以尝试替换自动完成对象 查看全文

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