{"id":1269,"date":"2022-10-12T18:52:59","date_gmt":"2022-10-12T17:52:59","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=1269"},"modified":"2022-10-12T19:55:53","modified_gmt":"2022-10-12T18:55:53","slug":"timers-general-2","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/timer-and-timing\/timers-general-2","title":{"rendered":"Timers General"},"content":{"rendered":"\n<p>The normal timers (system.timers.timer) are not accurate on fast timings. The thread sleep instruction timer also is often not. A minimum resolution may be 15mS or it may 55mS. Also it seems that if you specify a time of say 10mS, this will get rounded up to match the nearest time resolution \u2013 basically crap! A good resource on this: http:\/\/www.codeproject.com\/KB\/cs\/LP_TimerTest.aspx<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Pausing In A Function<\/h4>\n\n\n\n<p>See sleep in threads<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Global Timers<\/h4>\n\n\n\n<p>time_since_start = (clock_timer \u2013 start_at_time_value);<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Not so accurate timeout timer<\/h4>\n\n\n\n<p>Note that this timer has a worst case resolution of 500mS so not good for fast timing requirements<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tint StartTime;\n\tStartTime = System.Environment.TickCount;\n\twhile (1)\n\t{\n\t\tSystem.Windows.Forms.Application.DoEvents();\t\/\/(Neded in case what your waiting for occurs on same thread)\n\t\tif ((System.Environment.TickCount - StartTime) &gt; 500)\t\t\/\/&lt;&lt; Set mS timeout value\n\t\t{\n\t\t\t\/\/TIMED OUT\n\t\t}\n\t}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Multimedia timers<\/h4>\n\n\n\n<p>Allow applications to schedule timer events with the greatest resolution (or accuracy) possible for the hardware platform. These timer services are useful for applications that demand high-resolution timing. For example, a MIDI sequencer requires a high-resolution timer because it must maintain the pace of MIDI events within a resolution of 1 millisecond.<br>Each multimedia Timer instance runs in its own thread; it doesn\u2019t matter which thread the Timer was created in.<br>Warning \u2013 this type of timer has the potential to cause problems as its so powerful. If your calling it very fast then ensure the function that is called every roll over is fast.<br>The Win32 multimedia timer is not part of the .NET Framework. However, by using the .NET interoperability services, the multimedia timer can be brought into the .NET fold.<br>Note that MSDN says this type of timer is obsolete and to use another timer. However, without this timer there is no other timer that allows you to create events with this level of accuracy. The only other accurate timer is the stopwatch class but that can\u2019t be used to create events. Therefore it makes sense to use this even with the obsolete notice as its not obsolete yet and they will need to provide something instead if they do obsolete it.<\/p>\n\n\n\n<p>Int Note \u2013 We have a class that provides this timer for the Int Circ Array Tracker Range Finder project. Lots of time spent researching. These we\u2019re the 2 very helpful links code is based on:<br>http:\/\/www.codeguru.com\/forum\/showthread.php?t=385546<br>http:\/\/www.codeproject.com\/KB\/cs\/LP_TimerTest.aspx<br>http:\/\/www.codeproject.com\/KB\/miscctrl\/lescsmultimediatimer.aspx<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The normal timers (system.timers.timer) are not accurate on fast timings. The thread sleep instruction timer also is often not. A minimum resolution may be 15mS or it may 55mS. Also it seems that if you specify a time of say 10mS, this will get rounded up to match the nearest time resolution \u2013 basically crap! [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[],"class_list":["post-1269","post","type-post","status-publish","format-standard","hentry","category-timer-and-timing"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/1269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=1269"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/1269\/revisions"}],"predecessor-version":[{"id":1272,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/1269\/revisions\/1272"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=1269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=1269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=1269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}