I know the problem pretty well, I have some knowledge about developing videogames, and this was one of my first problems, it has its own history:
In the old time of DOS a videogame, a music player, or a network application for this matter has full control over the machine, no need of timers, later, on windows the API included timers but they wasn't fast enough because they are going through the message pool, so developers stayed on D.O.S for multimedia, Microsoft wasn’t very happy with the matter, so they included something called multimedia timers, that was the beginning of the Windows Games SDK (now DirectX). I don't know if .NET uses multimedia timers, you’ll need PInvoke and marshalling to use them on your own on .NET, the reference is here: http://msdn.microsoft.com/en-us/library/ms712704(VS.85).aspx You can also use DirectX, but that isn't funny only for a serial port. There is another problem, is that the time got on DateTime.Now() is being cached, with exactly 15ms precision (that has something to do with threading, I don't remember very well), but windows can calculates the real time, so you need to ask it to do it for you, I'm showing the code below, make sure to use it to test the .NET timer before trying multimedia timers. Own my own word of advice, using a second thread with an infinite loop, using a flag to know when to yield, and when to stop, an Application.DoEvents() each loop, and the way to measure time said below to adjust intervals, end up being faster than any timer, but is big effort (more to debug it than to write it). Ok, the following is the time mesuring technique I've being talking about, It's the code for .NET, wrote on my own (it’s wrote for VB.NET for your confort, tested and working, no need to mess with this code): Option Strict On Option Explicit On <DebuggerNonUserCode()> Public Module Ticker Private Declare Function GetTickCount Lib "kernel32" () As Integer Private Declare Function QueryPerformanceFrequency Lib "kernel32" (ByRef X As Int64) As Boolean Private Declare Function QueryPerformanceCounter Lib "kernel32" (ByRef X As Int64) As Boolean Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer) ''' <summary> ''' Return the number of milisecounds from the start of the system. (HiRes) ''' </summary> Public Function GetTime() As Double On Error Resume Next Dim T As Int64 Dim R As Int64 If QueryPerformanceCounter(T) Then If QueryPerformanceFrequency(R) Then GetTime = (T / R) * 1000 Exit Function End If End If Return GetTickCount End Function ''' <summary> ''' Return the number of milisecounds from the start of the system. ''' </summary> Public Function GetTicks() As Double On Error Resume Next Sleep(0) Return GetTickCount End Function End Module 'Any problems, any question, just post below, (avoid keeping all the text quoted, it's annoying) 'Theraot ^_^ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/DotNetDevelopment You may subscribe to group Feeds using a RSS Feed Reader to stay upto date using following url <a href="http://feeds.feedburner.com/DotNetDevelopment"> http://feeds.feedburner.com/DotNetDevelopment</a> -~----------~----~----~----~------~----~------~--~---
