0

I Got a Timer With Interval = 1

Interval 1 = 1 millisecond ?

if Interval 1 is not 1 millisecond ,
So tell me which control interval = 1ms

code:

Imports System.Globalization

Public Class Form1
    'Default Time To Start From
    Dim time As String = "00:00:00,000" 'Start From Here

    'Label
    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        Timer1.Start() 'Run The Timer On Click
    End Sub

    'TIMER
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        'Timer Interval = 1

        Dim ci = CultureInfo.InvariantCulture

        Dim original As TimeSpan = TimeSpan.ParseExact(time, "hh\:mm\:ss\,fff", ci) 'ParseExact

        Dim difference As TimeSpan = TimeSpan.FromMilliseconds(1) ' = 1  Millisecond

        Dim final = original

        final = original + difference ' connect between original to difference !(00:00:00,000 + 1 MS = 00:00:00,001)!

        Dim output As String = final.ToString("hh\:mm\:ss\,fff", ci) 'convert to the format (  = 00:00:00,001  ) (Back It To The Right Format)

        time = output '!!Update!! the Time String from 00:00:00,000 To 00:00:00,001 |||| And in the Next Time 00:00:00,001 + 1 = 00:00:00,002

        Label1.Text = time 'Show the Time String in the label

    End Sub

End Class

As you see - Im Useing Regular Timer With Interval 1 ,
But i think that it worng because timer not counting milliseconds

if you got advice ,tell me.

nnm
  • 865
  • 1
  • 8
  • 9
  • 5
    [From MSDN](http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx) `The Windows Forms Timer component is single-threaded, and is limited to an accuracy of 55 milliseconds. If you require a multithreaded timer with greater accuracy, use the Timer class in the System.Timers namespace.` – Steve Jun 14 '12 at 11:00
  • you got example to System.Timers? i need timer(1ms) – nnm Jun 14 '12 at 11:01
  • Show us the code that creates the timer and starts it ticking. It might be in `Main`. It'll include something like `Timer1.Interval = 1;`. – Gareth McCaughan Jun 14 '12 at 11:02
  • Or don't bother, since as Steve says this sort of timer will do you no good if you really need an event every millisecond. I am fairly sure that `System.Timers` won't do better than about 15ms, so that won't meet your needs either. You might want to look at http://stackoverflow.com/questions/3744032/why-are-net-timers-limited-to-15-ms-resolution for a bit more information. – Gareth McCaughan Jun 14 '12 at 11:05

2 Answers2

1

The description of the interval property from MSDN is:

Gets or sets the time, in milliseconds, before the Tick event is raised relative to the last occurrence of the Tick event.

However (as Steve pointed out in his comment):

The Windows Forms Timer component is single-threaded, and is limited to an accuracy of 55 milliseconds. If you require a multithreaded timer with greater accuracy, use the Timer class in the System.Timers namespace

Taken from http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx

The System.Timers.Timer class referred to is described here: http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx

Jon Egerton
  • 40,401
  • 11
  • 97
  • 129
  • 2
    @Steve: Sorry - didn't see your comment till after I posted this (was off the top of the screen!). Have given credit. – Jon Egerton Jun 14 '12 at 11:05
-1
    Imports System.Globalization


Public Class Form1
    Dim time As String = "00:00:00:00"
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        Dim ci = CultureInfo.InvariantCulture

        Dim original As TimeSpan = TimeSpan.ParseExact(time, "dd\:hh\:mm\:ss", ci) 'ParseExact

        Dim difference As TimeSpan = TimeSpan.FromSeconds(1) ' = 1  Millisecond

        Dim final = original

        final = original + difference ' connect between original to difference !(00:00:00,000 + 1 MS = 00:00:00,001)!

        Dim output As String = final.ToString("dd\:hh\:mm\:ss", ci) 'convert to the format (  = 00:00:00,001  ) (Back It To The Right Format)

        time = output '!!Update!! the Time String from 00:00:00,000 To 00:00:00,001 |||| And in the Next Time 00:00:00,001 + 1 = 00:00:00,002

        Label1.Text = time 'Show the Time String in the label

    End Sub
End Class

Here's working script. IDK why it works but it works! :)