1

I'm trying to make Timer with an Interval less than 1 Ms.

My Attempt:

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

  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    ProgressBar1.Increment(+1)
    If ProgressBar1.Value = 100 Then
        Timer1.Stop()
        ProgressBar1.Value = 0
        MessageBox.Show("Done, 1 Ms")
    End If
End Sub

When i utilize a "0000001" interval, the interval value returned "1".

My main purpose is to make a timer run as Nanoseconds to increase a label's text (+1) faster than 1 ms. I know it will make (+1000) for every 1 second, but I need make it faster than 1 ms.

So, is it possible that the timer can be faster than 1ms?

Impurity
  • 1,037
  • 2
  • 16
  • 31
James.Alocard
  • 67
  • 1
  • 6
  • 1
    If you actually need an interval less than 1 millisecond then you obviously cannot use a WinForms `Timer`. The question is, do you actually need such an interval? What practical use would it be to you? – jmcilhinney Aug 12 '18 at 05:28
  • i really need it, Such A things will shorten codes with speed that timer to take less time than.it token – James.Alocard Aug 12 '18 at 05:43
  • for example i used timer As interval "1", And made timer increase label number + 1, so it made 1 sec = 1000 label number, i need it make more like = 1 sec will add 1000000 Number, everysecond – James.Alocard Aug 12 '18 at 05:45
  • "Such A things will shorten codes with speed " What do your mean? If you share a little code to illustrate, maybe we can help some other way. – Mary Aug 12 '18 at 05:46
  • 1
    As far as I know, the minimum interval for a .net timer is a millisecond, but no built in timer implementation is that accurate. – Zohar Peled Aug 12 '18 at 05:51
  • 1
    I'm afraid that that's just silly. You don't need that at all. How could a human being even discern 1000 changes to a `Label` in one second, never mind more? It would be nothing but a blur even then. What you're asking for is pointless as well as impossible. Even if you were to use a high-precision timer with a resolution of less than one millisecond, the idea that you could update your UI that often indicates that you don't understand how these things work. There's a reason that the effective minimum interval for a WinForms `Timer` is ~50 ms. Anything less is of no practical use. – jmcilhinney Aug 12 '18 at 06:06
  • i just post what specific i want to make.that label more fast. so is there nothing, or what specific i can search to help it me out. – James.Alocard Aug 12 '18 at 06:10
  • 6
    Yes, you posted what you WANT. That's not what you NEED. Even if the Timer could raise events more often, it takes time to update the UI. Given that a human being can't even properly discern 1000 changes a second, having more would be useless. It might seem like a cool idea but it is completely useless. Even if you could do it, you wouldn't be able to tell the difference. – jmcilhinney Aug 12 '18 at 06:22
  • Yep, just set the interval as 100ms and make your increments 100000 instead of 1. That's the only way you'll get code that appears to produce the result you're asking for, and as others have said, even if the UI supported higher refresh rates, it's doubtful your monitor does (high end gaming monitors top out at 240Hz currently, I believe) and the human eye definitely doesn't. – Damien_The_Unbeliever Aug 12 '18 at 07:15
  • After writing a quick program that executes a do..loop to increment the progress bar and THEN display a MessageBox, the MessageBox was displayed before the ProgressBar had finished updating and the time it took to fill the progress bar was about 0.75 seconds. Conclusion, the repainting of the ProgressBar can't keep up with the execution of the program. Your chances of succeding with what you want is, I suspect, sadly zero. – David Wilson Aug 13 '18 at 19:51

1 Answers1

0

Unfortunately, this is not possible. See this msdn post for more reading on this issue. The StopWatch object could be use for measuring accurately, but there is no tick event that we see with the Timer.

Impurity
  • 1,037
  • 2
  • 16
  • 31