I have an application I am working on in WPF. It uses a serial port connection. I have created a class that wraps the serial port connection and manages buffers, etc.
I developed it when writing a C# WinForms application (.NET6). To allow the serial port events to update a textbox on the main form and send received bytes to a packet handler, I created a delegate and used BeginInvoke to run it. It worked just fine.
I took the same wrapper and included it in a new WPF application, without the textbox updates/packet handler included just to get started (so, only sending bytes out). It also ran fine. I uncommented the receive part of the wrapper, and all still compiles fine (but of course without code on the main form the incoming bytes were not being processed).
When I added the code to the main form to invoke the delegate, I got compile errors. At first, I thought it was a .NET6/.NET8 thing, but I opened the old project and changed the target .NET and it still ran fine.
So, I’m wondering if it’s a WinForms vs. WPF thing. The error is:
CS1501 No overload for method ‘BeginInvoke’ takes 3 arguments
Yet, the exact same code compiles and runs in the old project.
Here is the code in question:
void ProcessRecievedByte_Callback(object sender, byte rcvdByte)
{
this.BeginInvoke(new ES_UART.RxBufferRemoveByteEventHandler(ES_RxBufferProcessor), sender, rcvdByte);
}
void ES_RxBufferProcessor(object sender, byte e)
{
switch (receiveState)
{
case receive_state.WAITING_FOR_SOP:
if (e == '$')
{
receiveState = receive_state.IN_A_PACKET;
packetIndex = 0;
packetBuffer[packetIndex] = e;
packetIndex++;
}
break;
case receive_state.IN_A_PACKET:
if (packetIndex < MAX_PACKET_SIZE)
{
packetBuffer[packetIndex] = e;
packetIndex++;
}
if (e == 'n')
receiveState = receive_state.PACKET_RECIEVED;
break;
case receive_state.PACKET_RECIEVED:
break;
}
}
Any help would be appreciated.
Thanks