Skip to content

Commit

Permalink
DateTimeを用いた残り時間計算処理に変更した
Browse files Browse the repository at this point in the history
  • Loading branch information
kokeiro001 committed May 3, 2019
1 parent 7b85a3c commit a3c1fab
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions IksmClientDotNet.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 37,7 @@ class IksmService
private readonly string iksmSession;
private readonly string editHtmlPath;

private int remainSecond;
private DateTime lastUpdatedAt;
private bool updating = false;

public IksmService(string iksmSession, string editHtmlPath)
Expand All @@ -54,7 54,7 @@ public async Task Run()
System.Timers.Timer timer = new System.Timers.Timer(interval);

timer.Elapsed = Timer_Elapsed;
remainSecond = AutoUpdateIntervalSecond;
lastUpdatedAt = DateTime.Now;
timer.Start();

while (true)
Expand All @@ -78,7 78,7 @@ public async Task Run()

await Update();

remainSecond = AutoUpdateIntervalSecond;
lastUpdatedAt = DateTime.Now;
timer.Start();
}
}
Expand Down Expand Up @@ -136,7 136,7 @@ private async Task Update()

private async void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
remainSecond--;
var remainSecond = (int)(lastUpdatedAt.AddSeconds(AutoUpdateIntervalSecond) - DateTime.Now).TotalSeconds;
if (remainSecond > 0)
{
Console.CursorLeft = 0;
Expand All @@ -145,7 145,8 @@ private async void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e
}

await Update();
remainSecond = AutoUpdateIntervalSecond;

lastUpdatedAt = DateTime.Now;
}

private void InitializeConsoleMode()
Expand Down

0 comments on commit a3c1fab

Please sign in to comment.