shizuka.a


Hello all. I would like to enquire how I can set a delay in between chunks of code.

For example, after some code which interacts with a server, I am supposed to get a corresponding information from the server before it is appropriate to proceed on to the next part of the code. As the server response is not immediate, therefore an arbitrary delay is needed.

What is the proper code format that I need to add  I can't seem to find the documentation in the help file. Thanks in advance.



Re: How do I set delay between code?

Brendan Grant


The easiest way is often to simply do a sleep:

System.Threading.Thread.Sleep(1000)






Re: How do I set delay between code?

spotty

Only use this for very small delays as it suspends the entire thread from doing anything.

Otherwise if its a longer delay then consider using timers.






Re: How do I set delay between code?

Mitch Wardrop

I use a loop with a application.doevents in it, pauses the code but leaves the gui active. I do it in milliseconds generally... 1000 milliseconds = 1 second.

Dim Timer As DateTime = Now.AddMilliseconds(2000)
do
application.doevents()
until now > timer





Re: How do I set delay between code?

spotty

Use sparingly - as application.dovents has a potential to slow down a machine dramatically when placed in a fast running loop.





Re: How do I set delay between code?

DMan1

shizuka.a wrote:
...after some code which interacts with a server,

What is the proper code format that I need to add

The correct answer to your question is dependent upon how you are interacting with the server (ie what communications protocol are you using)...both tcp/ip and serial communications can be setup with events that respond to data recieved