Thursday, December 11, 2008

Lengthy Loops in vb.net

To keep your application perform a lengthy loops and also to keep your computer running and not hanging add the following line of code to the end of the loop and your computer will not freeze when the loop is running. It might slow down the looping but that is better than your computer freezing and locking you up.

In the for loop “i” and “n” are pre defined integers.

For i = 0 to n
…….
…….
Application.DoEvents()

Next

This will make sure that your computer is doing all its normal events during the “for loop” and it will not freeze. Right now when I am writing this, my computer is performing a lengthy for loop that is going on since two hours and my computer is still operational. In the back end the “for loop” is still running.

No comments: