- Notifications
You must be signed in to change notification settings - Fork0
nikvoronin/timers-are-not-what-they-seem
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Analysis of the .NET timers with 1ms tick size:
- System.Timers.Timer
- System.Threading.Timer
- Multimedia Timer imported from
winmm.dll
- TwinCAT 3. Soft Real-Time System
- Dedicated Thread
If you don't have Jupiter Notebooks installed locally, just use onlineJupyter NBViewer
System.Timers.Timer
andSystem.Threading.Timer
are limited with 15.6 ms by default.Multimedia Timer
. Always stable but legacy.- TwinCAT3 notifications. Not good at client side.
- Independed threads. Not stable at heavy load.
Conclusion. Should use legacyMultimedia Timer
or modern real-time systems like TC3.
Acquiring high-resolution time stamps -- 31-05-2018
Results of some quick research on timing in Win32 by Ryan Geiss -- 16 August 2002 (...with updates since then)
Real-Time Systems with Microsoft Windows CE 2.1 -- 06/29/2006
docx
Timers, Timer Resolution, and Development of Efficient Code -- June 16, 2010
Loads all cpu's cores w/ 100%
while(!token.IsCancellationRequested){Parallel.For(0,Environment.ProcessorCount,(i)=>{doublea=1000.0;for(intj=0;j<10_000_000;j++){if(token.IsCancellationRequested)break;a/=j*(i+1);}});}
SeeCpuBurner.cs
Legacy functions from early versions of Windows
[DllImport("winmm.dll",SetLastError=true,EntryPoint="timeSetEvent")]internalstaticexternUInt32TimeSetEvent(UInt32msDelay,UInt32msResolution,MultimediaTimerCallbackcallback,refUInt32userCtx,UInt32eventType);[DllImport("winmm.dll",SetLastError=true,EntryPoint="timeKillEvent")]internalstaticexternvoidTimeKillEvent(UInt32uTimerId);
System tick and PLC-Runtime both are 1 millisecond.
PROGRAMMAINVAR tick: BOOL;END_VARtick:=NOT tick;END_PROGRAM
AdsClientclient=newAdsClient();client.Connect(AmsPort.R0_RTS+1);client.AdsNotification+=(s,e)=>DoTick();varnotiSets=newNotificationSettings(AdsTransMode.OnChange,1,0);varh_tick=client.AddDeviceNotification("MAIN.tick",1,notiSets,null);
About
Analysis of the .NET timers with 1ms tick size
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.