diff --git a/Switch_Toolbox_Library/Forms/Custom/TreeViewCustom.cs b/Switch_Toolbox_Library/Forms/Custom/TreeViewCustom.cs index 4c990346..eee21d36 100644 --- a/Switch_Toolbox_Library/Forms/Custom/TreeViewCustom.cs +++ b/Switch_Toolbox_Library/Forms/Custom/TreeViewCustom.cs @@ -191,8 +191,13 @@ namespace Toolbox.Library if (Thread != null && Thread.IsAlive) Thread.Abort(); + this.BeginUpdate(); + Thread = new Thread((ThreadStart)(() => { + List treeNodes = new List(); + List imageIcons = new List(); + 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(); diff --git a/Switch_Toolbox_Library/Toolbox.Library.dll b/Switch_Toolbox_Library/Toolbox.Library.dll index 0967d73e..28939ad0 100644 Binary files a/Switch_Toolbox_Library/Toolbox.Library.dll and b/Switch_Toolbox_Library/Toolbox.Library.dll differ diff --git a/Switch_Toolbox_Library/Toolbox.Library.pdb b/Switch_Toolbox_Library/Toolbox.Library.pdb index d186863e..e8ce8ef7 100644 Binary files a/Switch_Toolbox_Library/Toolbox.Library.pdb and b/Switch_Toolbox_Library/Toolbox.Library.pdb differ