I have an object which can be called MyResponse.
{
"TimeStampA": "2022-01-01 08:00:00.000",
"TimeStampB": "2022-01-01 08:00:00.100"
}
The response is created by a service A (which set TimeStampA
property) and then forwarded to service B (which set TimeStampB
property).
Service A and service B are running on the same server.
TimeStampA
and TimeStampB
are both set using DateTime.Now
function.
Problem : when the frequency of MyResponse publication is very high, i can see that in some cases, TimeStampB < TimeStampA
I found this article telling that DateTime.Now
can return the same value if called repeatedly in a short time interval.
https://learn.microsoft.com/en-us/dotnet/api/system.datetime.now?redirectedfrom=MSDN&view=net-7.0#System_DateTime_Now
It seems to explain why TimeStampB < TimeStampA
in some cases ?
So, how to set the timestamp with precision ? Stopwatch seems more appropriate for durations, but the items are manipulated in 2 services.
My goal is to calculate the duration between TimeStampA
and TimeStampB
Thanks