In my application, I have a class that is responsible for all database actions. It is called from the main class and uses delegates to call methods after the action completes. Since it is asynchronous, I have to use invoke in my GUI, so I created a simple extension method:
public static void InvokeIfRequired<T>(this T c, Action<T> action) where T: Control { if (c.InvokeRequired) { c.Invoke(new Action(() => action(c))); } else { action(c); } }
This works fine when I try to call it in a text box:
textBox1.InvokeIfRequired(c => { c.Text = "it works!"; });
but when I try to call it on ToolStripStatusLabel or ToolStripProgressBar, I get an error:
The type "System.Windows.Forms.ToolStripStatusLabel" cannot be used as you enter the parameter "T" in the generic type or method 'SimpleApp.Helpers.InvokeIfRequired (T, System.ction)'. There is no implicit link translation from 'System.Windows.Forms.ToolStripStatusLabel' to 'System.Windows.Forms.Control'.
I know this is probably a simple fix, but I just can handle it: /
source share