Skip to content

Commit

Permalink
Merge pull request #1106 from VladiStep/progressBarResettingFix
Browse files Browse the repository at this point in the history
Progress bar resetting fix.
  • Loading branch information
Grossley authored Nov 11, 2022
2 parents 8761628 + 5ba85b4 commit 7e1183d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
23 changes: 17 additions & 6 deletions UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2303,29 +2303,40 @@ public void DisableAllSyncBindings() //disable all sync. bindings

private void ProgressUpdater()
{
DateTime prevTime = default;
Stopwatch sw = new();
Stopwatch swTimeout = null;
int prevValue = 0;

while (true)
{
sw.Restart();

if (cToken.IsCancellationRequested)
{
if (prevValue >= progressValue) //if reached maximum
if (prevValue >= progressValue) // if reached maximum
{
sw.Stop();
swTimeout?.Stop();
return;
}
else
{
if (prevTime == default)
prevTime = DateTime.UtcNow; //begin measuring
else if (DateTime.UtcNow.Subtract(prevTime).TotalMilliseconds >= 500) //timeout - 0.5 seconds
if (swTimeout is null)
swTimeout = Stopwatch.StartNew(); // begin measuring
else if (swTimeout.ElapsedMilliseconds >= 500) // timeout - 0.5 seconds
{
sw.Stop();
swTimeout.Stop();
return;
}
}
}

UpdateProgressValue(progressValue);

prevValue = progressValue;

Thread.Sleep(100); //10 times per second
Thread.Sleep((int)Math.Max(0, 33 - sw.ElapsedMilliseconds)); // ~30 times per second
}
}
public void StartProgressBarUpdater()
Expand Down
11 changes: 1 addition & 10 deletions UndertaleModTool/Windows/LoaderDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,7 @@ public void ReportProgress(double value) //update without status text changing
}
public void UpdateValue(double value)
{
if (value - ProgressBar.Value <= 1) //if value not changed or changed by 1
{
ProgressBar.Value = value;
}
else
{
DoubleAnimation animation = new(value, TimeSpan.FromMilliseconds(100)); //time is the same as in "ProgressUpdater()"
ProgressBar.BeginAnimation(ProgressBar.ValueProperty, animation); //smooth progress change
}

ProgressBar.Value = value;
TaskbarItemInfo.ProgressValue = value / ProgressBar.Maximum;
}

Expand Down

0 comments on commit 7e1183d

Please sign in to comment.