c# - operation getting slower of fetching data from database and showing them into auto-complete text-box using textBox_TextChanged event -


i developing winform app.i have textbox.in text box user can write it.my job match every letter , comparing text database , show suggestion of 10 words similar of text database.what did that:

  private void textbox1_textchanged(object sender, eventargs e)     {          string = textbox1.text;          // autocomplete textbox         autocompletestringcollection namescollection = new autocompletestringcollection();         sqlceconnection con = new sqlceconnection(@"data source=" + directory.getcurrentdirectory() + @"\database\ghfghfgh.sdf;password=1020;");         con.open();          sqlcecommand cmnd = con.createcommand();         cmnd.commandtype = commandtype.text;          int fetchamount = 10;         string userinput = textbox1.text;         cmnd.commandtext = string.format("select top ({0}) english dic english '{1}%'",             fetchamount.tostring(), userinput);          sqlcedatareader dreader=null;         dreader = cmnd.executereader();          if (dreader !=null)         {             while (dreader.read())                 namescollection.add(dreader["english"].tostring());          }         else         {            // messagebox.show("data not found");         }         dreader.close();          textbox1.autocompletemode = autocompletemode.suggest;         textbox1.autocompletesource = autocompletesource.customsource;         textbox1.autocompletecustomsource = namescollection;         // end of autocomplete          con.close();     } 

but getting slower.sometimes crashes.i need solution .what can make faster????

what can make faster , efficient????

hard current design. however, think common use timer (system.windows.forms.timer).

private void textbox1_textchanged(object sender, eventargs e) {     timertext.stop();     timertext.start(); }  private void timertext_ticket(object sender, eventargs e) // forget event args type {     //do operation     timertext.stop(); } 

this way, won't query each time make text change, instead spend brief period of time before execution.


Comments