|
Thanks, you reminded me how the OS do it's work.
Then the DateTime.Now property, in fact, can't get precise timer stamp, right? since it depends on the thread calling it, and OS.
|
|
|
|
|
You get the time when it is being proccessed if that matters, the trouble is you dont know exactly when youll get it.
|
|
|
|
|
econy wrote: I wonder if the Now property is not precise
There's TickCount[^], and there's Ticks[^]. You want the latter.
Do take in account that you're not guaranteed to get CPU-time every 200ms. If it must react to each event of the device, the best path would be to write a device-driver. That would take you beyond VB though.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
You're welcome
|
|
|
|
|
Since Windows is not a "real-time" operating system, it's impossible to get a precise 200ms tick on any timer.
|
|
|
|
|
On most computers the minimum increment of the DateTime.Now property is 15.625ms, so on average your timestamps will be accurate to about half of that. A 200ms timer won't fire at exactly 200ms (probably 190-210) but your observation of a consistently prolonged interval is indicative of a delayed timer event. The most likely reason for this is that the time taken to read the device and process the data is actually 500-700ms.
To find out what's going on, a bit more data needs to be gathered within your timer event handler.
PSEUDOCODE
==========
OnTimerTick()
ts1 = GetTimeStamp
ReadDevice
ts2 = GetTimeStamp
ProcessData
ts3 = GetTimeStamp
and then calculate
readingTime = ts2 - ts1
processingTime = ts3 - ts2
You can use the System.Diagnostics.Stopwatch class to get microsecond accurate timestamps.
Alan.
|
|
|
|
|
Read MSDN example:
Imports System
Imports System.Diagnostics
Imports System.Threading
Class Program
Shared Sub Main(ByVal args() As String)
Dim stopWatch As New Stopwatch()
stopWatch.Start()
Thread.Sleep(10000)
stopWatch.Stop()
Dim ts As TimeSpan = stopWatch.Elapsed
Dim elapsedTime As String = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
Console.WriteLine( "RunTime " + elapsedTime)
End Sub
End Class
Then I try to create a new console project to test the example, when I build it, I got an error message: SubMain was not found in "testStopWatch.Module1".
According to the example, it should be a console project, but dont know why VSTUDIO need a module.
modified 11-Apr-13 15:34pm.
|
|
|
|
|
I think is should read
Module Program
anmd not
Class PRogram
|
|
|
|
|
If you open the projects' properties, you'll find that they entry-point is "Module1". Change that, or change the code to using a module;
Namespace testStopWatch
Public Module1
Shared Sub Main(ByVal args() As String)
End Sub
End Module
End Namesapce
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I dont get that when I open a new project in VB console:
Module Module1
Sub Main()
End Sub
End Module
Why the sheard sub main?
|
|
|
|
|
You're absolutely right, it shouldn't be "shared" when in a module, only when in a class. My bad
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Ah, I though I had missed a lesson there
|
|
|
|
|
Kenneth Haugland wrote: Ah, I though I had missed a lesson there Noes, I'm just bad at remembering those lessons. And, there's no compiler-warnings when editing code in a post
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Just figured out, from my previous posts, that it dosnt spell check either.
|
|
|
|
|
..hehe, I used Google Translate on "sheard" and realized it had to be "shared" when typing
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Does VB.Net has a timer function, I want to use a timer like:
timer.start();
do sth1
timer.now() in milliseonds
do sth2
timer.now() in milliseconds
d0 sth3
timer.now() in milliseconds.
Now I use Now() function, but I felt this function can't produce precise result.
And I googled stopwatch class, but it needs start(), stop() repeatedly.
modified 11-Apr-13 14:27pm.
|
|
|
|
|
econy wrote: And I googled stopwatch class, but it needs start(), stop() repeatedly. Not according to the manual;
You can query the properties Elapsed, ElapsedMilliseconds, and ElapsedTicks while the Stopwatch instance is running or stopped.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The Stopwatch[^] doesn't need repeated calls to Start[^] and Stop[^]. At most, if you want to reset the elapsed time between readings, you would call the Restart[^] method.
Dim timer As Stopwatch = Stopwatch.StartNew()
do sth1
timer.ElapsedMilliseconds
timer.Restart()
do sth2
timer.ElapsedMilliseconds
timer.Restart()
do sth3
timer.ElapsedMilliseconds
timer.Stop()
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
What are you looking to do with this timer? Your post doesn't make any sense as "timer.now()" is meaningless. There is no "Now()" property or method on any of the Timer classes.
There are various types of timers in the .NET Framework, each is designed to handle different situations, but I don't think that's what you're trying to do.
If you're talking about starting a stopwatch and getting an elapsed time at various points in a process, then you use the Stopwatch class. To get your interval times, you just get the value in the Stopwatch.Elapsed, Stopwatch.EllapsedMilliseconds, or EllapsedTicks properties. You don't have to stop the stopwatch to do that.
|
|
|
|
|
Thanks, Now I understand the stopwatch class
|
|
|
|
|
I using ; 1 Textbox (for keyword), 1 Button (for Search Button), 1 ListView (Data List) and 1 label (for Result/Search information).
Thanks for help before
Best Regards
VB2010 Newbie
|
|
|
|
|
..and what have you tried upto now? Have you worked with a ListView before?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello,
I created an application for Windows CE 5.0 in VB. The class application AppCEClass is inherited from Microsoft.WindowsCE.Forms.MessageWindow. I have a problem to launch an application, because something like this does not work:
Public Shared Sub Main()
Application.Run(New AppCEClass())
End Sub
Windows does not recognize the class name and throw error AppCEClass() cannot be converted on System.Windows.Forms.Form.
What to do?
modified 11-Apr-13 9:22am.
|
|
|
|