Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove another use of Environment.TickCount in favour of DateTime.

  • Loading branch information...
commit bffece7cc809ad0bd12031bddf8b04c8e7da14c3 1 parent dd7545a
Alan McGovern alanmcgovern authored
Showing with 10 additions and 10 deletions.
  1. +10 −10 src/MonoTorrent/MonoTorrent.Common/SpeedMonitor.cs
20 src/MonoTorrent/MonoTorrent.Common/SpeedMonitor.cs
View
@@ -40,7 +40,7 @@ public class SpeedMonitor
private int speed;
private int[] speeds;
private int speedsIndex;
- private int lastUpdated;
+ private DateTime lastUpdated;
private long tempRecvCount;
@@ -66,7 +66,7 @@ public SpeedMonitor(int averagingPeriod)
if (averagingPeriod < 0)
throw new ArgumentOutOfRangeException ("averagingPeriod");
- this.lastUpdated = Environment.TickCount;
+ this.lastUpdated = DateTime.UtcNow;
this.speeds = new int [Math.Max (1, averagingPeriod)];
this.speedsIndex = -speeds.Length;
}
@@ -89,17 +89,12 @@ public void Reset()
this.total = 0;
this.speed = 0;
this.tempRecvCount = 0;
- this.lastUpdated = Environment.TickCount;
+ this.lastUpdated = DateTime.UtcNow;
this.speedsIndex = -speeds.Length;
}
private void TimePeriodPassed(int difference)
{
- lastUpdated = Environment.TickCount;
-
- if (difference < 0)
- difference = 1000;
-
int currSpeed = (int)(tempRecvCount * 1000 / difference);
tempRecvCount = 0;
@@ -134,13 +129,18 @@ private void TimePeriodPassed(int difference)
public void Tick()
{
- int difference = Environment.TickCount - lastUpdated;
- if (difference >= 800 || difference < 0)
+ DateTime old = lastUpdated;
+ lastUpdated = DateTime.UtcNow;
+ int difference = (int) (lastUpdated - old).TotalMilliseconds;
+
+ if (difference > 800)
TimePeriodPassed(difference);
}
+ // Used purely for unit testing purposes.
internal void Tick (int difference)
{
+ lastUpdated = DateTime.UtcNow;
TimePeriodPassed (difference);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.