This code is completely independent from all time changes (e.g. Utility.SetLocalTime/TimeService.SetTimeZoneOffset),
but Utility.GetMachineTime().Ticks is the timestamp at processing time, not the interrupt time.
Using the time parameter will be more accurate , so lets try:
Provided that execution time of Utility.GetMachineTime().Ticks and DateTime.Now is a constant value, _Duration will be accurate.
But this code fails too, e.g TimeService.SetTimeZoneOffset(120) will affect DateTime.Now , but not the time parameter.
( DateTime.Now - time.Ticks is about "02:00:00.000xxx") .
Please note , both DateTime.Now and time are marked as local time (DateTimeKind = Local).
Why is time parameter's time always UTC? And if that is correct (i guess it is) , why DateTimeKind is not Utc?
Is there a property ("offset") inside the framework , so we can count back machine ticks from time parameter' ticks : MachineTtick= time.Ticks - "offset" ?
It would spare me some work to follow time changes / time zones / daylight-saving time..
Thank you very much in advance