mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 20:24:16 +01:00
fix(PluginImageCache): use thread instead of taks
This commit is contained in:
parent
47a2287e83
commit
08b0bc94c4
1 changed files with 12 additions and 11 deletions
|
|
@ -45,6 +45,7 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
|
|
||||||
private BlockingCollection<Func<Task>> downloadQueue = new();
|
private BlockingCollection<Func<Task>> downloadQueue = new();
|
||||||
private CancellationTokenSource downloadToken = new();
|
private CancellationTokenSource downloadToken = new();
|
||||||
|
private Thread downloadThread;
|
||||||
|
|
||||||
private Dictionary<string, TextureWrap?> pluginIconMap = new();
|
private Dictionary<string, TextureWrap?> pluginIconMap = new();
|
||||||
private Dictionary<string, TextureWrap?[]> pluginImagesMap = new();
|
private Dictionary<string, TextureWrap?[]> pluginImagesMap = new();
|
||||||
|
|
@ -61,11 +62,8 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
this.TroubleIcon = interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "troubleIcon.png"));
|
this.TroubleIcon = interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "troubleIcon.png"));
|
||||||
this.UpdateIcon = interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "updateIcon.png"));
|
this.UpdateIcon = interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "updateIcon.png"));
|
||||||
|
|
||||||
var task = new Task(
|
this.downloadThread = new Thread(this.DownloadTask);
|
||||||
() => this.DownloadTask(this.downloadToken.Token),
|
this.downloadThread.Start();
|
||||||
this.downloadToken.Token,
|
|
||||||
TaskCreationOptions.LongRunning);
|
|
||||||
task.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -91,6 +89,12 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
this.UpdateIcon?.Dispose();
|
this.UpdateIcon?.Dispose();
|
||||||
|
|
||||||
this.downloadToken?.Cancel();
|
this.downloadToken?.Cancel();
|
||||||
|
|
||||||
|
if (!this.downloadThread.Join(4000))
|
||||||
|
{
|
||||||
|
Log.Error("Plugin Image Download thread has not cancelled in time.");
|
||||||
|
}
|
||||||
|
|
||||||
this.downloadToken?.Dispose();
|
this.downloadToken?.Dispose();
|
||||||
this.downloadQueue?.CompleteAdding();
|
this.downloadQueue?.CompleteAdding();
|
||||||
this.downloadQueue?.Dispose();
|
this.downloadQueue?.Dispose();
|
||||||
|
|
@ -171,16 +175,13 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void DownloadTask(CancellationToken token)
|
private async void DownloadTask()
|
||||||
{
|
{
|
||||||
while (true)
|
while (!this.downloadToken.Token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (token.IsCancellationRequested)
|
if (!this.downloadQueue.TryTake(out var task, -1, this.downloadToken.Token))
|
||||||
return;
|
|
||||||
|
|
||||||
if (!this.downloadQueue.TryTake(out var task, -1, token))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await task.Invoke();
|
await task.Invoke();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue