

- Windows batch file time delay how to#
- Windows batch file time delay code#
- Windows batch file time delay windows#
Windows batch file time delay code#
Here's the code for a probe using the delay. I developed this delay code segment to adjust ping intervals in a "ping probe" that I use to check continuity of communications both intra-network and into the internet world. Select all Open in new window A Sample Application - A PING Probe REM On this machine the delay per ping is 16.3msec.
Windows batch file time delay windows#
The code one might use to test a Windows batch file to effect a delay would be: Implementing a Millisecond-Resolution Delay “-w” parameter is blank then it just doesn’t matter what you do with It can also be blank or it can be not used at all (which would suggest that the default of 4000 would be used). To get that number, we’ll run a little measurement batch program: So that will be the objective of the batch file we’ll develop here. First, we need to know the single-ping delay. Let’s assume that we want a delay of 333 milliseconds.
Windows batch file time delay how to#
Nonetheless, I figure it’s worth documenting and to make some suggestions regarding how to make use of it: You may have to be concerned about what the delay is going to be on a machine with other high-demand processes running.So, it may not be very accurate or stable.You have to determine what the delay is going to be on the machine it’s to be used on.So, it’s likely not very “portable”.I can only imagine that it’s machine dependent and I have to believe that it’s undocumented so one might only want to use it with some huge caveats: Using this form of the PING command results in a very short timeout. With -w but with no parameter accompanying “–w” then it looks like this: If the timeout in the PING command is blank, that is, if the command is structured Whether by a typo or some other insightful method, I discovered this (likely undocumented “feature”): (There is some unfortunate literature around that says it’s 1000 but that seems proven to be incorrect through good old-fashioned testing.) “-w” entry is omitted altogether, then the default timeout is 4000 milliseconds or 4 seconds. That could well be an unfortunate limitation for some.Ī Trick for Using PING for Batch File millisecond Delays So, while the times are expressed in milliseconds, they are only effected in ½ second chunks. If the timeout is 1000 or more, the timeout is ROUNDED DOWN to the nearest ½ second (500 milliseconds).If the timeout is 999 of less, 500 is the result.

If the timeout is 500 or less, 500 is the result.After seeing some unexpected results, I decided to measure the timeout times. So, one might think that “what you see is what you get”. The “xxxxx” is the timeout entered as expressed in milliseconds.

The common PING command set up to create a delay looks like this The first thing that I learned was that the PING timeout method doesn’t do what one might hope or think. So, it would appear to be a good mechanism to use for creating a delay with millisecond resolution. And, the timeout period is specified in an integer number of milliseconds. The PING timeout method uses a PING command to a non-existent IP address so that it has to wait to the end of its built-in or specified timeout period before finishing. An integer number of seconds.The most promising approach for millisecond-resolution delays seemed to be use of the PING command.
