optimize tasks
This commit is contained in:
@@ -75,6 +75,7 @@ namespace Pixiview.Illust
|
||||
protected double topOffset;
|
||||
|
||||
private T illustData;
|
||||
private ParallelTask task;
|
||||
|
||||
public IllustCollectionPage()
|
||||
{
|
||||
@@ -95,6 +96,11 @@ namespace Pixiview.Illust
|
||||
|
||||
public override void OnUnload()
|
||||
{
|
||||
if (task != null)
|
||||
{
|
||||
task.Dispose();
|
||||
task = null;
|
||||
}
|
||||
InvalidateCollection();
|
||||
Illusts = null;
|
||||
lastUpdated = default;
|
||||
@@ -559,7 +565,12 @@ namespace Pixiview.Illust
|
||||
|
||||
void DoLoadImages(IllustCollection collection)
|
||||
{
|
||||
ParallelTask.Start(0, collection.Count, Configs.MaxThreads, i =>
|
||||
if (task != null)
|
||||
{
|
||||
task.Dispose();
|
||||
task = null;
|
||||
}
|
||||
task = ParallelTask.Start(0, collection.Count, Configs.MaxThreads, i =>
|
||||
{
|
||||
if (!collection.Running)
|
||||
{
|
||||
@@ -716,11 +727,17 @@ namespace Pixiview.Illust
|
||||
}
|
||||
|
||||
private readonly object sync = new object();
|
||||
private volatile bool running;
|
||||
private bool running;
|
||||
|
||||
public bool Running
|
||||
{
|
||||
get => running;
|
||||
get
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
return running;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (sync)
|
||||
|
@@ -109,13 +109,6 @@ namespace Pixiview.Illust
|
||||
return;
|
||||
}
|
||||
await ScrollToTopAsync(scrollView);
|
||||
// release
|
||||
var collection = IllustCollection;
|
||||
if (collection != null)
|
||||
{
|
||||
collection.Running = false;
|
||||
IllustCollection = null;
|
||||
}
|
||||
startIndex = -1;
|
||||
nextIndex = 0;
|
||||
illustIds = null;
|
||||
|
@@ -128,6 +128,7 @@ namespace Pixiview.Illust
|
||||
private readonly ImageSource fontIconNotLove;
|
||||
private IllustUgoiraData ugoiraData;
|
||||
private Ugoira ugoira;
|
||||
private ParallelTask task;
|
||||
|
||||
private readonly object sync = new object();
|
||||
private int downloaded = 0;
|
||||
@@ -188,6 +189,15 @@ namespace Pixiview.Illust
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnUnload()
|
||||
{
|
||||
if (task != null)
|
||||
{
|
||||
task.Dispose();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
#if __IOS__
|
||||
protected override void OnPageTopMarginChanged(Thickness old, Thickness @new)
|
||||
{
|
||||
@@ -387,7 +397,12 @@ namespace Pixiview.Illust
|
||||
}
|
||||
}
|
||||
|
||||
ParallelTask.Start(0, items.Length, Configs.MaxPageThreads, i =>
|
||||
if (task != null)
|
||||
{
|
||||
task.Dispose();
|
||||
task = null;
|
||||
}
|
||||
task = ParallelTask.Start(0, items.Length, Configs.MaxPageThreads, i =>
|
||||
{
|
||||
DoLoadImage(i);
|
||||
return true;
|
||||
@@ -461,7 +476,6 @@ namespace Pixiview.Illust
|
||||
else
|
||||
{
|
||||
var val = downloaded / (float)pageCount;
|
||||
App.DebugPrint($"download progress: {val}");
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
ViewExtensions.CancelAnimations(progress);
|
||||
|
Reference in New Issue
Block a user