diff --git a/Pixiview/Illust/IllustCollectionPage.cs b/Pixiview/Illust/IllustCollectionPage.cs index e1bf2cd..6be9cb3 100644 --- a/Pixiview/Illust/IllustCollectionPage.cs +++ b/Pixiview/Illust/IllustCollectionPage.cs @@ -504,7 +504,7 @@ namespace Pixiview.Illust public abstract class IllustScrollableCollectionPage : IllustCollectionPage { protected const int SCROLL_OFFSET = 33; - protected static readonly object sync = new object(); + protected readonly object sync = new object(); private double lastScrollY = double.MinValue; private double offset; diff --git a/Pixiview/Illust/ViewIllustPage.xaml.cs b/Pixiview/Illust/ViewIllustPage.xaml.cs index 26a5683..5fd0a75 100644 --- a/Pixiview/Illust/ViewIllustPage.xaml.cs +++ b/Pixiview/Illust/ViewIllustPage.xaml.cs @@ -153,8 +153,10 @@ namespace Pixiview.Illust if (ugoira != null) { - ugoira.TogglePlay(false); IllustItem.IsPlaying = false; + ugoira.TogglePlay(false); + ugoira.Dispose(); + ugoira = null; } if (saveFavorites) diff --git a/Pixiview/Utils/HttpUtility.cs b/Pixiview/Utils/HttpUtility.cs index 3040a5b..be7507b 100644 --- a/Pixiview/Utils/HttpUtility.cs +++ b/Pixiview/Utils/HttpUtility.cs @@ -292,8 +292,10 @@ namespace Pixiview.Utils } } - public class Ugoira + public class Ugoira : IDisposable { + private readonly object sync = new object(); + private readonly IllustUgoiraBody ugoira; private readonly IllustDetailItem detailItem; private readonly ImageSource[] frames; @@ -315,21 +317,39 @@ namespace Pixiview.Utils Task.Run(LoadFrames); } + public void Dispose() + { + lock (sync) + { + if (IsPlaying) + { + TogglePlay(false); + } + } + if (timer != null) + { + timer.Dispose(); + } + } + public void TogglePlay(bool flag) { - if (IsPlaying == flag) + lock (sync) { - return; - } - if (flag) - { - IsPlaying = true; - timer.Change(0, Timeout.Infinite); - } - else - { - IsPlaying = false; - timer.Change(Timeout.Infinite, Timeout.Infinite); + if (IsPlaying == flag) + { + return; + } + if (flag) + { + IsPlaying = true; + timer.Change(0, Timeout.Infinite); + } + else + { + IsPlaying = false; + timer.Change(Timeout.Infinite, Timeout.Infinite); + } } } @@ -359,9 +379,12 @@ namespace Pixiview.Utils private void OnTimerCallback(object state) { - if (!IsPlaying) + lock (sync) { - return; + if (!IsPlaying) + { + return; + } } ImageSource frame; @@ -384,7 +407,13 @@ namespace Pixiview.Utils i = 0; } index = i; - timer.Change(info.delay, Timeout.Infinite); + lock (sync) + { + if (IsPlaying) + { + timer.Change(info.delay, Timeout.Infinite); + } + } } private const int BUFFER_SIZE = 300000;