5

Good day all!

I am trying to make my app to call a function n times per second. I use a System.Timers.Timer for that purpose (I made it to expire n times per second by setting its interval to 1000/n ms). The maximum calls per second I get is 65. I've tryed to use System.Threading.ThreadPool.QueueUserWorkItem, I've tryed starting new Threads each time the timer expires. Well it starts with 100 calls per second for the first few seconds and then slows down to 65.

I even tryed not using timer and made it with Thread.sleep like it was advised in one of the posts here: it didn't help at all.

BTW I once made similar things in Java (SchedulerExecutorService) and I had up to 1000 calls per second with no problem.

What else could help me to solve the problem?


Update:

Thanks to all, I've found the solution here:

The Multimedia Timer for the .NET Framework

They use winmm.dll functions for Timer class realization and it works perfectly for me.

Direvius
  • 427
  • 3
  • 17
  • Have a look at this http://msdn.microsoft.com/en-us/magazine/cc164015.aspx – John Aug 26 '11 at 09:57
  • Have you checked the `Elapsed` event which would be called after setting the interval, maybe thats what you need – V4Vendetta Aug 26 '11 at 09:59
  • I can't give you a real answer but I think I read somewhere that you can use the XNA framework for this kind of high-precision timer. – Random Dev Aug 26 '11 at 09:59
  • See the dupe. In Windows Timers and Sleep are limited to the 15-20 ms timeslot. – H H Aug 26 '11 at 10:07
  • Thanks for that link, it have brought some light. What I haven't yet understood is how to set that limit to a smaller value. It was mentioned there how to do that with windows multimedia API. Is there a way to make it with C#? – Direvius Aug 26 '11 at 10:41

0 Answers0