Handling threads in C# wpf application -
I am creating a C # wpf application with Visual Studio 2012. Text box is a two text box called Inbox and TextboxOptput. My job is when I'm typing in textboxInput, this description should be searched in real time in a text box output to find a database. Since it takes a moment, it slows down my typing speed which the user never wants.
This thing happens when the user is typing "Foo", it searches for "F", then "fo" and then "foo". It has database entries for everyone, the user just does not want to see the details of "Foo" to others, but I can not predict where he will stop typing. I want to give him a smooth typing without cold. So in my Test Changed event I find it with a thread and if it comes to the Change Text Event (another letter type), it kills the previous thread and runs a new thread.
My current approach.
Private zero text boxoxput_TextChanged (Object Sender, Text ChangeEngenseAgages E) {//textBoxOutput.Text = search (textBoxInput.Text); // PREVEIOUS ATTITUDE // Current View New Thread (Rep. (Search (TextBox Encoded Text);}). Start ();} Would you please enter that code inside Can help me
- My current code gives me an exception "Calling thread can not access this object because it is a separate thread owner" How to handle it?
- How can I apply the killing thread of last thread? (I am starting one :))
- Are there any other good ways to achieve my work?
You can do this:
Thread thread; Bull flag = false; Public Manvindo () {Initialization (); Thread = new thread (new threadstart (search)); Thread.Start (); } Private zero text boxoxput_TextChanged (Object Sender, TextChangedEventArgs e) {If (Flag) Return; Flag = true; } Private zero search () {while (true) {if (flag) {string result = search (textbox.Intext.text); this. Dispatcher. Basic Invoc (New Action (() = & gt; {textBoxOutput.Text = Result;})); Flag = false; } Thread Sleep (200); }} Never do this: It kills the previous thread and runs a new thread .
Comments
Post a Comment