Make ProgressNotification's status and progress thread-safe

Quite regularly a task will hold a reference to a progress notification and udpate it as progress is made. Therefore these operations should be thread-safe.
This commit is contained in:
Dean Herbert 2017-10-18 10:07:20 +09:00
parent 120d3fbbec
commit 518e5a2245
1 changed files with 36 additions and 36 deletions

View File

@ -25,10 +25,7 @@ public string Text
public float Progress
{
get { return progressBar.Progress; }
set
{
progressBar.Progress = value;
}
set { Schedule(() => progressBar.Progress = value); }
}
protected override void LoadComplete()
@ -44,41 +41,44 @@ public virtual ProgressNotificationState State
get { return state; }
set
{
bool stateChanged = state != value;
state = value;
if (IsLoaded)
Schedule(() =>
{
switch (state)
{
case ProgressNotificationState.Queued:
Light.Colour = colourQueued;
Light.Pulsate = false;
progressBar.Active = false;
break;
case ProgressNotificationState.Active:
Light.Colour = colourActive;
Light.Pulsate = true;
progressBar.Active = true;
break;
case ProgressNotificationState.Cancelled:
Light.Colour = colourCancelled;
Light.Pulsate = false;
progressBar.Active = false;
break;
}
}
bool stateChanged = state != value;
state = value;
if (stateChanged)
{
switch (state)
if (IsLoaded)
{
case ProgressNotificationState.Completed:
NotificationContent.MoveToY(-DrawSize.Y / 2, 200, Easing.OutQuint);
this.FadeOut(200).Finally(d => Completed());
break;
switch (state)
{
case ProgressNotificationState.Queued:
Light.Colour = colourQueued;
Light.Pulsate = false;
progressBar.Active = false;
break;
case ProgressNotificationState.Active:
Light.Colour = colourActive;
Light.Pulsate = true;
progressBar.Active = true;
break;
case ProgressNotificationState.Cancelled:
Light.Colour = colourCancelled;
Light.Pulsate = false;
progressBar.Active = false;
break;
}
}
}
if (stateChanged)
{
switch (state)
{
case ProgressNotificationState.Completed:
NotificationContent.MoveToY(-DrawSize.Y / 2, 200, Easing.OutQuint);
this.FadeOut(200).Finally(d => Completed());
break;
}
}
});
}
}
@ -232,4 +232,4 @@ public enum ProgressNotificationState
Completed,
Cancelled
}
}
}