I want to update the SerialPort DataReceived event handler user interface. I found the problem because the event handler was implicitly started on another thread in the form, so instead of just updating the user interface ...
myLabel.Text = "Some text";
... I had to take the following approach:
InvokeControlAction<Label>(myLabel, lbl=> lbl.Text= "Some text");
...
public static void InvokeControlAction<t>(t cont, Action<t> action) where t : Control
{
if (cont.InvokeRequired)
{
cont.Invoke(new Action<t, Action<t>>(InvokeControlAction),
new object[] { cont, action });
}
else
{
action(cont);
}
}
So far so good ... However, now I want to update ToolStripStatusLabel - using the same approach, it gives "there is no implicit link conversion between errors between ToolStripStatusLabel and Forms.Control".
From what I read, problems arise because you cannot call ToolStripStatusLabel.
So how do I deal better?
: .. , .
1:. , InvokeControlAction ToolStripStatusLabel, , .
. , .
ExtensionMethod ( ExtensionMethods), InvokeOnToolStripItem, 'using ExtensionMethods;' :
tsStatusValue.InvokeOnToolStripItem(ts => ts.Text = "ALARM signal received");