Link to home
Start Free TrialLog in
Avatar of Dgleich
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...
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Hello Dgleich,

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
Avatar of Dgleich
Dgleich

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
Avatar of obrienslalom
obrienslalom
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dgleich

ASKER

In the thread the thread is writing text to textbox
Avatar of Dgleich

ASKER

Thanks for the thread information solved using
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
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.