Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment.TickCount #15

Open
loonwong opened this issue Jul 2, 2020 · 2 comments
Open

Environment.TickCount #15

loonwong opened this issue Jul 2, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@loonwong
Copy link

loonwong commented Jul 2, 2020

Hello!

We are using an implementation for C# and I would like to draw your attention to the following code:

int Elapsed = Environment.TickCount;
...
Expired = Environment.TickCount - Elapsed > Timeout;

This is because Environment.TickCount returns values from Int32.MinValue to Int32.MaxValue. Therefore, if the system has been running for 24.9 days, the counter will turn negative and the expression Expired = Environment.TickCount-Elapsed > Timeout will return false for the next 24.9 days.

Instead of Environment.TickCount, I would suggest using a static instance of Stopwatch (which is run once) to get uptime milliseconds.

@fbarresi fbarresi added the enhancement New feature or request label Jul 3, 2020
@fbarresi
Copy link
Owner

fbarresi commented Jul 3, 2020

Hi!

I guess, you are referring to this line, right?

This method would cause a single transmission error if the TickCount overflows exactly while waiting for data and I think any application resilient enough will keep working anyway.
Honestly I use sharp7 in many application that runs in high frequency polling over many years and I didn't get any problem at this point.

I understand the problem, I will fix it.
Thank you for your suggestion.

Best regards,

Federico

@Peter-B-
Copy link

Peter-B- commented Apr 9, 2021

I don't think that this will cause an issue due to the way .net handles integer arithmetic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants