Dgleich
asked on
Gui freezing
I am programming in Visual Basic 2008 and when I press the button the for loop starts...
I wanna make Gui accessible while the loop is running...
I wanna make Gui accessible while the loop is running...
ASKER
Thanks for your comment but I alerady tryed that I put and the application is accesible every 2 or 3 seconds for about 1 sec...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
In the thread the thread is writing text to textbox
ASKER
Thanks for the thread information solved using
System.Windows.Forms.Contr ol.CheckFo rIllegalCr ossThreadC alls = False
System.Windows.Forms.Contr
Can you post the function that has the loop? Maybe there is something that can be done differently that you don't need a loop for. Maybe a callback or other event based solution...
I will agree with RedEagle. The fact that you are writing to a textbox from another thread. My assumption is that you are not real familiar with threading in general. Allow me to give you a quick contrived example that does data validation.
[Textbox_1 reads "hello!"]
After the user typed the text, the original GUI thread (T1) spawns the validation routine on a separate thread (T2). As the validation routine is chugging through its complicated validation code, the user decides to make a change to the textbox. He is allowed to make this change on T1 and changes the textbox value to "hi". He continues filling out other information on the form when your validation routine comes to the end of it's work. It noticed that the value in textbox_1 had an invalid exclamation mark, so it changes the text to "invalid". Notice that the user already noticed his mistake and corrected it. However, the validation routine actually overwrote his correction. He has to now go back again and retype "hi" in the textbox, is annoyed by your software, hates your company, and avoids you forever.
Long story short, unless you are careful about the synchronization of your data, avoid writing to elements owned by T1 from T2. Any shared items between two theads needs to be synchronized when both are allowed to write to them.
[Textbox_1 reads "hello!"]
After the user typed the text, the original GUI thread (T1) spawns the validation routine on a separate thread (T2). As the validation routine is chugging through its complicated validation code, the user decides to make a change to the textbox. He is allowed to make this change on T1 and changes the textbox value to "hi". He continues filling out other information on the form when your validation routine comes to the end of it's work. It noticed that the value in textbox_1 had an invalid exclamation mark, so it changes the text to "invalid". Notice that the user already noticed his mistake and corrected it. However, the validation routine actually overwrote his correction. He has to now go back again and retype "hi" in the textbox, is annoyed by your software, hates your company, and avoids you forever.
Long story short, unless you are careful about the synchronization of your data, avoid writing to elements owned by T1 from T2. Any shared items between two theads needs to be synchronized when both are allowed to write to them.
Then you need to include:
Application.DoEvents
inside your loop. This will allow the application to respond to other events whilst the loop is executing.
Regards,
TimCottee