VB.net Timer help
j
Sterling Heights, MI Icrontian
I'm writing a program in VB.net. It requires the use of a timer to execute some code. However the timer module they have is not nearly as fast as I want it to be. I want to have a timer that has a resolution of a uS or faster. Is there a way to use a "Tick" of the system clock? Any help would be great
j
also known as MicroMan
j
also known as MicroMan
0
Comments
ps: i moved this into the programming forum where it will probably be better served.
well, I dont a timer, but I coded a 'time waster' in programming last year when I got bored, took like 5 minutes, and the speed was adjustable, but would be dependant on the processor speed.
I just coded two for loops and nested one inside the other, and made a few variables, our assignment was to move a ball around the screen, so I made the speed adjustable. Im sure this isnt what you are looking for, as I am a relative greenhorn to programming. I cant wait to get to college though, I am even excited about AP CS this year, a whole year focusing on java, it should be good.:D
Someone gave me some code based on a function in kernel32, but I've only used it a couple of times, so I'm not sure if this is exactly what you're looking for. I don't think it'll make a differnece, but I used this in VBA(6).
Private Declare Function GetTickCount Lib "kernel32" () As Long
Then have something call GetTickCount and store the long integer it returns. Call GetTickCount again, and subtract the two numbers to get the difference.
It might be in mS, not uS, though.
you could build your own timer, i'm not sure if you could do real-time in VB though. you'll definitely need a knowledge of either real time programming or at least threaded programming, depending on what you want to do....
are you looking for some sort of scheduler or are you wanting to do something at a specific time? like is this a situation where you want something along the lines of
"run program A precisely 1450 june 2 2007"
or more like
"run program B as soon as program A gets done"
or a
"run program A for exactly 100 clock ticks then run program B for exactly 100 clock ticks then run A again"?
after a certain number of ticks run the lines of code below. 1 tick would = 1uS or what ever the tick is. I just can't have the tick as 1mS, well it actually is about 10 to 20 ms when you sent the timer.interval value down to 1.
[PHP]
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
' Place this code in any Sub or Function
Dim lngStart As Long
Dim lngFinish As Long
Dim lngCounterOne As Long
Dim lngCounterTwo As Long
' Record the start "time"
lngStart = GetTickCount()
' Some process that you want to time
For lngCounterOne = 1 To 1000000
For lngCounterTwo = 1 To 5
Next lngCounterTwo
Next lngCounterOne
' Record the finish "time"
lngFinish = GetTickCount()
' Display the difference
MsgBox CStr(lngFinish - lngStart)
[/PHP]
play around with that and see what you can do
How do I generate an event when a certain amount of ticks go by. I want to use it as a timer control. The problem is the timer control says you can set the interval to 1mS, but it actually is 20mS.
--edit : didn't mean to include that link
http://www.sysinternals.com/Information/NativeApi.html
or straight from the horse's mouth
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/overview_of_the_windows_api.asp
I don't know anything about events, though.