Changed: thread helper

This commit is contained in:
Ray 2020-08-23 15:49:22 +01:00
parent f82dfbc308
commit 9e6992acd2
3 changed files with 58 additions and 88 deletions

View File

@ -822,17 +822,7 @@ namespace bzit.bomg
this.ApplicationMode = AppMode.Open; this.ApplicationMode = AppMode.Open;
} }
if (this.InvokeRequired) RyzStudio.Windows.Forms.ThreadControl.SetText(this, Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name);
{
this.Invoke(new MethodInvoker(() =>
{
this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name;
}));
}
else
{
this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name;
}
} }
protected void loadBookmarkFile_ForRYZ(string filename, string password = "") protected void loadBookmarkFile_ForRYZ(string filename, string password = "")
@ -977,17 +967,7 @@ namespace bzit.bomg
this.ApplicationMode = AppMode.New; this.ApplicationMode = AppMode.New;
} }
if (this.InvokeRequired) RyzStudio.Windows.Forms.ThreadControl.SetText(this, Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name);
{
this.Invoke(new MethodInvoker(() =>
{
this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name;
}));
}
else
{
this.Text = Path.GetFileNameWithoutExtension(filename) + " - " + Resources.app_name;
}
} }
protected void openBookmark(TreeNode node) protected void openBookmark(TreeNode node)

View File

@ -71,6 +71,56 @@ namespace RyzStudio.Windows.Forms
return n; return n;
} }
public static TreeNode Add(TreeNode control, string key, string text, int imageIndex, int selectedImageIndex)
{
TreeNode rs = null;
if (control.TreeView.InvokeRequired)
{
control.TreeView.Invoke(new MethodInvoker(() => {
rs = control.Nodes.Add(key, text, imageIndex, selectedImageIndex);
}));
}
else
{
rs = control.Nodes.Add(key, text, imageIndex, selectedImageIndex);
}
return rs;
}
public static TreeNode Add(TreeView control, string key, string text, int imageIndex, int selectedImageIndex)
{
TreeNode rs = null;
if (control.InvokeRequired)
{
control.Invoke(new MethodInvoker(() => {
rs = control.Nodes.Add(key, text, imageIndex, selectedImageIndex);
}));
}
else
{
rs = control.Nodes.Add(key, text, imageIndex, selectedImageIndex);
}
return rs;
}
public static void Add(Control parentControl, ImageList control, string key, Image value)
{
if (parentControl.InvokeRequired)
{
parentControl.Invoke(new MethodInvoker(() => {
control.Images.Add(key, value);
}));
}
else
{
control.Images.Add(key, value);
}
}
public static int Add(TreeNode control, TreeNode value) public static int Add(TreeNode control, TreeNode value)
{ {
int n = -1; int n = -1;

View File

@ -166,17 +166,7 @@ namespace RyzStudio.Windows.Forms
TreeNode tn2 = addFolderPath(viewModel.TreeviewPath); TreeNode tn2 = addFolderPath(viewModel.TreeviewPath);
if (this.InvokeRequired) ThreadControl.Add(tn2, tn);
{
this.Invoke(new MethodInvoker(() =>
{
tn2.Nodes.Add(tn);
}));
}
else
{
tn2.Nodes.Add(tn);
}
this.HasChanged = true; this.HasChanged = true;
} }
@ -217,17 +207,7 @@ namespace RyzStudio.Windows.Forms
public void Clear() public void Clear()
{ {
if (this.InvokeRequired) ThreadControl.Clear(this);
{
this.Invoke(new MethodInvoker(() =>
{
this.Nodes.Clear();
}));
}
else
{
this.Nodes.Clear();
}
this.HasChanged = true; this.HasChanged = true;
} }
@ -666,17 +646,7 @@ namespace RyzStudio.Windows.Forms
} }
else else
{ {
if (this.InvokeRequired) ThreadControl.Add(this, this.ImageList, model.SiteAddress, rs);
{
this.Invoke(new MethodInvoker(() =>
{
this.ImageList.Images.Add(model.SiteAddress, rs);
}));
}
else
{
this.ImageList.Images.Add(model.SiteAddress, rs);
}
return this.ImageList.Images.IndexOfKey(model.SiteAddress); return this.ImageList.Images.IndexOfKey(model.SiteAddress);
} }
@ -689,17 +659,7 @@ namespace RyzStudio.Windows.Forms
return (int)IconSet.Default; return (int)IconSet.Default;
} }
if (this.InvokeRequired) ThreadControl.Add(this, this.ImageList, model.SiteAddress, bmp);
{
this.Invoke(new MethodInvoker(() =>
{
this.ImageList.Images.Add(model.SiteAddress, bmp);
}));
}
else
{
this.ImageList.Images.Add(model.SiteAddress, bmp);
}
iconDatabase.AddIcon(model.SiteAddress, rawData); iconDatabase.AddIcon(model.SiteAddress, rawData);
@ -739,17 +699,7 @@ namespace RyzStudio.Windows.Forms
{ {
if (!this.Nodes.ContainsKey(item)) if (!this.Nodes.ContainsKey(item))
{ {
if (this.InvokeRequired) ThreadControl.Add(this, item, decodePath(item), (int)IconSet.Root, (int)IconSet.Root);
{
this.Invoke(new MethodInvoker(() =>
{
this.Nodes.Add(item, decodePath(item), (int)IconSet.Root, (int)IconSet.Root);
}));
}
else
{
this.Nodes.Add(item, decodePath(item), (int)IconSet.Root, (int)IconSet.Root);
}
} }
tn = this.Nodes[item]; tn = this.Nodes[item];
@ -758,17 +708,7 @@ namespace RyzStudio.Windows.Forms
{ {
if (!tn.Nodes.ContainsKey(item)) if (!tn.Nodes.ContainsKey(item))
{ {
if (this.InvokeRequired) ThreadControl.Add(tn, item, decodePath(item), (int)IconSet.Folder1, (int)IconSet.Folder2);
{
this.Invoke(new MethodInvoker(() =>
{
tn.Nodes.Add(item, decodePath(item), (int)IconSet.Folder1, (int)IconSet.Folder2);
}));
}
else
{
tn.Nodes.Add(item, decodePath(item), (int)IconSet.Folder1, (int)IconSet.Folder2);
}
} }
tn = tn.Nodes[item]; tn = tn.Nodes[item];