Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
hii ,
i have 2 form ( form1 & form2) and both have one one textbox each ...

My Question is How To Run Both the textbox_textchange event of both the Form At on Go ... so that my searching time should reduce ...

Prome wat m facing is when textbox1 event is running textbox2 event runs after the first one finished ... and wat i wNt is to run both form event at onces ...

need help ..
Thanks in advance
Posted
Comments
Richard MacCutchan 7-May-15 3:40am    
You can't, since the interaction with the user is only single thread.
Ralf Meier 7-May-15 3:47am    
I don't exactly understand your question.
What should the different Button's (the action-scripts of them) do ?

1 solution

First, please let me clarify one thing: A button-click or some other UI-interaction causes an event and the event causes your event-handler-method to be executed. So you don't "run the events".

If you do not implement some kind of multi-threading, then the UI-thread is the only thread running in your application-process - and it can only do one thing at a time. And as you probably already have noticed, it also can't update your UI or react to user-input while being busy with executing some method that you've triggered with a previous button-click (or whatever).

If you want to be able to do multiple things simultaneously, you need to deal with multi-threading. There are various ways to do that. I would recommend you to use a (or multiple) "BackgroundWorker" (because it's an easy way for a beginner).

Let's say you click button "A" then your UI-thread would execute the event-handler-method for "button A click". There you would start a BackgroundWorker that does the actual searching (or whatever). That frees your UI-thread to resume its main purpose, to update the UI and react to user input. Then you can click on button "B" to start another BackgroundWorker that does the other search (or whatever). When a BackgroundWorker finishes, it can call back to your UI-thread (with yet another event-handler-method) in order to display the result on your form.

For examples of using a BackgroundWorker please take a look here:
http://www.dotnetperls.com/progressbar[^]
http://stackoverflow.com/a/1068743/4320056[^]
http://www.codeproject.com/Messages/5050414/Re-WinForms-Update-A-Dialog.aspx[^]

Please give it a shot and if you can't get it to work, feel free to post another question here and include your code so we can see where the problem is.
 
Share this answer
 
Comments
Member 10521418 7-May-15 11:47am    
thnxxx you sascha i will get a try on it and said true that i must use background worker and dear m not beginner as some small things sometimes won't come on mind buz of lots of tensions in mind...but anyways thnxxs i will give a try and if it will not work i will back to you ... thnxxs
regards
Sascha Lefèvre 7-May-15 12:02pm    
Alright! You're welcome!
Member 10521418 9-May-15 3:13am    
hey sascha , i have used backgroundworker and the result is good but now i am getting some prome to insert text into the textbox from within the backgroundworker in dowork event.
Member 10521418 9-May-15 3:27am    
while by using runworkercompleted it work fine and update my textbox but with hang of,form . it hangs the form until the it finished the search ... dowork event not hangfor as sec but it wont update the textbox....
Member 10521418 9-May-15 6:23am    
solved ... by using invoke within backgroundworker ....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900