locked
How to set timer resolution to 0.5ms ?

    Question

  • I have low latency application working already with 1ms timer resolution. W2008R2.

    The minimal possible resolution is 0.5ms however.

    Is there a tool or advice on code which can set timer resolution to 0.5ms?

    Wednesday, June 30, 2010 8:15 AM

Answers

  • You may use NtSetTimerResolution function, try this:

     

            [DllImport("ntdll.dll", EntryPoint = "NtSetTimerResolution")]

            public static extern void NtSetTimerResolution(uint DesiredResolution, bool SetResolution, ref uint CurrentResolution);

            private void Foo()

            {

                uint DesiredResolution = 9000;

                bool SetResolution= true;

                uint CurrentResolution = 0;

     

                NtSetTimerResolution(DesiredResolution, SetResolution, ref CurrentResolution);

     

            }


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by maxima Saturday, July 03, 2010 4:20 PM
    Thursday, July 01, 2010 10:23 AM

All replies

  • Hi,

    This aritcle discussed an implementation of High-Performance Timer in C# (using QueryPerformanceFrequency and QueryPerformanceCounter functions), is it what you are looking for?


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by maxima Wednesday, June 30, 2010 9:50 AM
    • Unmarked as answer by maxima Wednesday, June 30, 2010 9:50 AM
    Wednesday, June 30, 2010 8:42 AM
  • No Eric, I need to set the clock resolution to 0.5ms.
    Wednesday, June 30, 2010 9:51 AM
  • so, what do you meaning by refering to the word "timer", something like System.Timer? could you please let us know what the scenario is.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, June 30, 2010 10:37 AM
  • the system timer. look here: http://technet.microsoft.com/en-us/sysinternals/bb795535.aspx ClockRes reports the timer resolution. It can be set through Win32 but the minimum it take is 1ms.

    My timer can be set down to 0.5ms but I dont know how.

    Wednesday, June 30, 2010 11:16 AM
  • You may use NtSetTimerResolution function, try this:

     

            [DllImport("ntdll.dll", EntryPoint = "NtSetTimerResolution")]

            public static extern void NtSetTimerResolution(uint DesiredResolution, bool SetResolution, ref uint CurrentResolution);

            private void Foo()

            {

                uint DesiredResolution = 9000;

                bool SetResolution= true;

                uint CurrentResolution = 0;

     

                NtSetTimerResolution(DesiredResolution, SetResolution, ref CurrentResolution);

     

            }


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by maxima Saturday, July 03, 2010 4:20 PM
    Thursday, July 01, 2010 10:23 AM
  • That is exactly what I was looking for! Thanks a bunch!
    Saturday, July 03, 2010 4:20 PM