Skip to content

Commit

Permalink
Trying to fix #1 by removing uses of StopWatch class
Browse files Browse the repository at this point in the history
Bump version
  • Loading branch information
maxisoft committed Apr 3, 2022
1 parent 8ffeb25 commit 03fa833
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ASFFreeGames/ASFFreeGamesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private async void CollectGamesOnClock(object? source) {
Bot[] reorderedBots;

lock (BotContexts) {
TimeSpan orderByRunKeySelector(Bot bot) => BotContexts.TryGetValue(bot.BotName, out var ctx) ? ctx.RunElapsed : TimeSpan.MaxValue;
long orderByRunKeySelector(Bot bot) => BotContexts.TryGetValue(bot.BotName, out var ctx) ? ctx.RunElapsedMilli : long.MaxValue;
int comparison(Bot x, Bot y) => orderByRunKeySelector(y).CompareTo(orderByRunKeySelector(x)); // sort in descending order
reorderedBots = Bots.ToArray();
Array.Sort(reorderedBots, comparison);
Expand Down
12 changes: 4 additions & 8 deletions ASFFreeGames/BotContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ internal sealed class BotContext : IDisposable {
private readonly WeakReference<Bot> Bot;
private readonly TimeSpan BlacklistTimeout = TimeSpan.FromDays(1);
private readonly CompletedAppList CompletedApps = new();
private Stopwatch LastRun = new();
private long LastRunMilli;

public BotContext(Bot bot) {
Bot = new WeakReference<Bot>(bot);
LastRun.Start();
NewRun();
}

private string CompletedAppFilePath() {
Expand Down Expand Up @@ -107,11 +107,7 @@ public async Task SaveToFileSystem(CancellationToken cancellationToken = default

public void Dispose() => CompletedApps.Dispose();

public TimeSpan RunElapsed => LastRun.Elapsed;
public long RunElapsedMilli => Environment.TickCount64 - LastRunMilli;

public void NewRun() {
// note LastRun.Restart() got trimmed out
LastRun.Reset();
LastRun.Start();
}
public void NewRun() => LastRunMilli = Environment.TickCount64;
}
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<PluginName>ASFFreeGames</PluginName>
<Version>1.2.0.0</Version>
<Version>1.2.1.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 03fa833

Please sign in to comment.