timeBeginPeriod (winmm)
Last changed: -213.183.86.244

.
Summary
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:

None.

Notes:

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

  try
  {
    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)
  {
    Console.WriteLine(oException.Message);
  }
  finally
  {
    if(oWriter != null)
      oWriter.Close();
  }

  MM_EndPeriod(1);
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation