digitaldrew
Well-known member
- Joined
- Nov 10, 2012
- Messages
- 167
- Programming Experience
- Beginner
I want my program to start as close to 13:00:00.000 as possible. To achieve this, I setup a basic while loop..
When running the code above, I found it takes roughly .005 or so to iterate through the loop. With that in mind, the idea of getting it to start at exactly 13:00:00.000 every single time is probably not possible, which is fine because I just want to be very close. Here is a little excerpt of my log from a random test..
My question pertains specifically to the last two lines. The loop does its last check at 17:40:30.003, but then has to iterate and go back up to the beginning of the loop again before it finally exits and starts the thread. Because of that, you can see it actually wastes .006 of time between the last "WAITING at" and the "THREADS STARTED at"
I decided to try two different solutions to fix this. The first was changing my While loop to a Do While loop where I could do my time comparison at the end of the loop instead of the start. I've also tried doing a basic Do loop and then putting an IF statement in there at the end. Here is the code I've tried:
and
However, it doesn't seem to fix this issue. It still takes additional time after the last check to iterate through the loop and start the thread. Here's a log from each of the loops above..
Do While Loop
Do Loop
Considering the Do While loop is actually comparing the time at the end of the loop and not the beginning, shouldn't it start right away without iterating through again? For instance, if my last check is at .004 shouldn't my thread be starting right away at .004 or .005 and not .012 like in my log above? All I want to do is eliminate the small amount of time between the last "WAITING at" and the "THREADS STARTED at"...
VB.NET:
Dim time As DateTime = DateTime.Now
While time.ToString("HH:mm:ss.fff") <= txtStartTime.Text.Trim
time = DateTime.Now
txtLog.AppendText("WAITING at: " & Format(Now, "HH:mm:ss.fff") & vbCrLf)
End While
Thread1.RunWorkerAsync()
txtLog.AppendText("THREADS STARTED at: " & Format(Now, "HH:mm:ss.fff") & vbCrLf)
When running the code above, I found it takes roughly .005 or so to iterate through the loop. With that in mind, the idea of getting it to start at exactly 13:00:00.000 every single time is probably not possible, which is fine because I just want to be very close. Here is a little excerpt of my log from a random test..
VB.NET:
WAITING at: 17:40:29.974
WAITING at: 17:40:29.980
WAITING at: 17:40:29.984
WAITING at: 17:40:29.989
WAITING at: 17:40:29.994
WAITING at: 17:40:29.999
WAITING at: 17:40:30.003
THREADS STARTED at: 17:40:30.009
My question pertains specifically to the last two lines. The loop does its last check at 17:40:30.003, but then has to iterate and go back up to the beginning of the loop again before it finally exits and starts the thread. Because of that, you can see it actually wastes .006 of time between the last "WAITING at" and the "THREADS STARTED at"
I decided to try two different solutions to fix this. The first was changing my While loop to a Do While loop where I could do my time comparison at the end of the loop instead of the start. I've also tried doing a basic Do loop and then putting an IF statement in there at the end. Here is the code I've tried:
VB.NET:
Dim time As DateTime = DateTime.Now
Do
time = DateTime.Now
txtLog.AppendText("WAITING at: " & Format(Now, "HH:mm:ss.fff") & vbCrLf)
Loop While time.ToString("HH:mm:ss.fff") <= txtStartTime.Text.Trim
Thread1.RunWorkerAsync()
txtLog.AppendText("THREADS STARTED at: " & Format(Now, "HH:mm:ss.fff") & vbCrLf)
and
VB.NET:
Dim time As DateTime = DateTime.Now
Do
time = DateTime.Now
txtLog.AppendText("WAITING at: " & Format(Now, "HH:mm:ss.fff") & vbCrLf)
If time.ToString("HH:mm:ss.fff") >= txtStartTime.Text.Trim Then Exit Do
Loop
Thread1.RunWorkerAsync()
txtLog.AppendText("THREADS STARTED at: " & Format(Now, "HH:mm:ss.fff") & vbCrLf)
However, it doesn't seem to fix this issue. It still takes additional time after the last check to iterate through the loop and start the thread. Here's a log from each of the loops above..
Do While Loop
VB.NET:
WAITING at: 17:54:29.967
WAITING at: 17:54:29.973
WAITING at: 17:54:29.978
WAITING at: 17:54:29.984
WAITING at: 17:54:29.991
WAITING at: 17:54:29.998
WAITING at: 17:54:30.004
THREADS STARTED at: 17:54:30.012
Do Loop
VB.NET:
WAITING at: 17:57:29.975
WAITING at: 17:57:29.980
WAITING at: 17:57:29.985
WAITING at: 17:57:29.991
WAITING at: 17:57:29.996
WAITING at: 17:57:30.000
THREADS STARTED at: 17:57:30.005
Considering the Do While loop is actually comparing the time at the end of the loop and not the beginning, shouldn't it start right away without iterating through again? For instance, if my last check is at .004 shouldn't my thread be starting right away at .004 or .005 and not .012 like in my log above? All I want to do is eliminate the small amount of time between the last "WAITING at" and the "THREADS STARTED at"...