Skip to content

Environment.TickCount #15

@loonwong

Description

@loonwong

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions