make ugoira disposable
This commit is contained in:
parent
da8da3be4d
commit
2fe66d4f8d
@ -504,7 +504,7 @@ namespace Pixiview.Illust
|
||||
public abstract class IllustScrollableCollectionPage<T> : IllustCollectionPage<T>
|
||||
{
|
||||
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;
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user