1
0
mirror of synced 2024-11-30 18:24:39 +01:00

Improve multiple image icon loading speed

This commit is contained in:
KillzXGaming 2019-08-04 14:26:52 -04:00
parent 575dfe521c
commit 2a19d4c75b
3 changed files with 49 additions and 3 deletions

View File

@ -191,8 +191,13 @@ namespace Toolbox.Library
if (Thread != null && Thread.IsAlive)
Thread.Abort();
this.BeginUpdate();
Thread = new Thread((ThreadStart)(() =>
{
List<TreeNode> treeNodes = new List<TreeNode>();
List<Image> imageIcons = new List<Image>();
foreach (TreeNode node in textureIconList.IconTextureList)
{
if (node is STGenericTexture)
@ -200,7 +205,8 @@ namespace Toolbox.Library
try
{
var image = ((STGenericTexture)node).GetBitmap();
AddImageOnThread(image, node);
treeNodes.Add(node);
imageIcons.Add(image);
}
catch (Exception ex)
{
@ -208,6 +214,34 @@ namespace Toolbox.Library
}
}
}
for (int i = 0; i < treeNodes.Count; i++)
{
AddImageOnThread(i, treeNodes[i]);
}
if (this.InvokeRequired)
{
this.Invoke((MethodInvoker)delegate
{
this.ImageList.Images.AddRange(imageIcons.ToArray());
});
}
for (int i = 0; i < treeNodes.Count; i++)
imageIcons[i].Dispose();
imageIcons.Clear();
treeNodes.Clear();
if (this.InvokeRequired)
{
this.Invoke((MethodInvoker)delegate
{
this.EndUpdate();
});
}
}));
Thread.Start();
}
@ -222,14 +256,26 @@ namespace Toolbox.Library
node.ImageIndex = this.ImageList.Images.Count;
node.SelectedImageIndex = node.ImageIndex;
this.ImageList.Images.Add(image);
var dummy = this.ImageList.Handle;
imgList.Images.Add(image);
image.Dispose();
});
}
}
public void AddImageOnThread(int index, TreeNode node)
{
if (this.InvokeRequired)
{
this.Invoke((MethodInvoker)delegate {
// Running on the UI thread
node.ImageIndex = this.ImageList.Images.Count + index;
node.SelectedImageIndex = node.ImageIndex;
});
}
}
public void ReloadImages(int Width = 22, int Height = 22)
{
imgList = new ImageList();