How can I suspend a Do While - Loop for a specific of time?
-
Hi! I have DO WHILE LOOP and I placed Application.Dovents necessarily inside the loop. I just wonder would it be possible to make the loop hanging for a specific of time but same time I should be able to perform other actions in application. I decided to use System.Threading.Thread.sleep() but it is locking the application for defined time and Application.Doevents becomes useless. I need your advice. The scenario is held inside a private procedure. I wish there would be a statement to suspend processing of a procedure inside the application for specific of time :laugh: Thank you all.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
-
Hi! I have DO WHILE LOOP and I placed Application.Dovents necessarily inside the loop. I just wonder would it be possible to make the loop hanging for a specific of time but same time I should be able to perform other actions in application. I decided to use System.Threading.Thread.sleep() but it is locking the application for defined time and Application.Doevents becomes useless. I need your advice. The scenario is held inside a private procedure. I wish there would be a statement to suspend processing of a procedure inside the application for specific of time :laugh: Thank you all.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
Would you not first create a new thread for your DO WHILE LOOP and System.Threading.Thread.sleep() that one and not the app. thread? Jelle
-
Would you not first create a new thread for your DO WHILE LOOP and System.Threading.Thread.sleep() that one and not the app. thread? Jelle
Thanks for replying. I am just new about threads in vb.net and I couldn't find an example how to create a new one. The application.wait also hangs the whole application. Actually it is a game project user versus to computer in making words with given letters. But it takes only a second for puter to come up with words. Therefore, I want to make puter waiting for a specific of time before it places words on the board. This action is held inside a Do WHILE LOOP and I eventually placed Application.Doevents for user inside the loop. The puter has to wait inside the loop. Eventually I can solve the problem but I was looking for a statement for that. Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
-
Thanks for replying. I am just new about threads in vb.net and I couldn't find an example how to create a new one. The application.wait also hangs the whole application. Actually it is a game project user versus to computer in making words with given letters. But it takes only a second for puter to come up with words. Therefore, I want to make puter waiting for a specific of time before it places words on the board. This action is held inside a Do WHILE LOOP and I eventually placed Application.Doevents for user inside the loop. The puter has to wait inside the loop. Eventually I can solve the problem but I was looking for a statement for that. Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
If your not running the code on a secondary thread then the only way I believe is what I think you've already done. Use a loop that loops for a specified period of time and use application.doevents inside the loop so it doesn't lock your application. If you use a secondary thread to do the processing you could just call threading.sleep. But doing so on the UI thread will as you've discovered cause the UI to appear hung. If you'd rather use a secondary thread look into the backgroundworker component. It's pretty easy to use.
-
Thanks for replying. I am just new about threads in vb.net and I couldn't find an example how to create a new one. The application.wait also hangs the whole application. Actually it is a game project user versus to computer in making words with given letters. But it takes only a second for puter to come up with words. Therefore, I want to make puter waiting for a specific of time before it places words on the board. This action is held inside a Do WHILE LOOP and I eventually placed Application.Doevents for user inside the loop. The puter has to wait inside the loop. Eventually I can solve the problem but I was looking for a statement for that. Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
With the additional info I believe your approach is over complicating things. I would use a new thread for a complicated and time consuming task where the app can do better things then just waiting. Yours however, if I understand you right, has a "simple" and "Quick" task you like to delay. Better not take that task and only start it after the delay? You could just use a timer to start it. If it is essential that the "computer" is producing it's answer character by character then maybe it is the "adding characters bit" you want to delay? This possibly allows a re-compute of the computer task if it needs to respond to users input. Is all that relevant? I am looking forward to your comments. Jelle
-
With the additional info I believe your approach is over complicating things. I would use a new thread for a complicated and time consuming task where the app can do better things then just waiting. Yours however, if I understand you right, has a "simple" and "Quick" task you like to delay. Better not take that task and only start it after the delay? You could just use a timer to start it. If it is essential that the "computer" is producing it's answer character by character then maybe it is the "adding characters bit" you want to delay? This possibly allows a re-compute of the computer task if it needs to respond to users input. Is all that relevant? I am looking forward to your comments. Jelle