timeBeginPeriod (winmm)
Last changed: -

The timeBeginPeriod function sets the minimum timer resolution for an application or device driver. Used to manipulate the timer frequency.

C# Signature:

[DllImport("winmm.dll", EntryPoint="timeBeginPeriod")]
public static extern uint MM_BeginPeriod(uint uMilliseconds);

VB Signature:

Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Integer) As Integer

User-Defined Types:



Also see TimeGetTime (MM_GetTime) and TimeEndPeriod (MM_EndPeriod)

Tips & Tricks:

Please add some!

Sample Code:

static void Main(string[] args)
  StreamWriter oWriter = null;
  MM_BeginPeriod(1); // set timer resolution to 1ms => freq=1000Hz

    oWriter = new StreamWriter(@"ticks.txt");
    // tickcount has resolution of 16.5ms, mmtime has 1ms
    for(int nLoop = 0; nLoop < 100000; nLoop++)
      oWriter.WriteLine("{0}: TickCount={1}, MMTime={2}", nLoop, Environment.TickCount, MM_GetTime());
  catch(IOException oException)
    if(oWriter != null)


Alternative Managed API:

Do you know one? Please contribute it!