AutoComplete Texbox error - write to protected memory

前端 未结 2 1772
情书的邮戳
情书的邮戳 2021-01-22 07:00

I have an autocompleate textbox that looks into a data base. Some times while I\'m typing I received the following error.

Attempted to read or write protected memory

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-22 07:19

    You can use lock:

    private void tBSearchName_TextChanged(object sender, EventArgs e)
    {
        lock(this) { /* do magic */
    }
    

    Do note that it's bad practice to perform long tasks in the event handlers. If the search takes more then 30ms, better use a worker thread.

提交回复
热议问题