You misunderstood
Control.Invoke
. This is not event invocation, so your
object sender
and
EventArgs
arguments are superfluous. Having this made-up artificial limitation, you have done bad thing: passing the text through the outer context relative to your method. Instead, you should use the event delegate with any signature you need:
string newData = SerialPort.ReadExisting();
this.Invoke(new System.Action<string>((data) => {
txtIncomingData.AppendText(data);
}), newData);
If you need to override the character, not append, assuming
txtIncomingData
is you text box, replace
txtIncomingData.AppendText(data);
with
txtIncomingData.Text = data;
—SA