0

I want to run a method inside serialport_DataReceived event.

public void Draw(byte[] data);

private void myPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
       this.Invoke(new EventHandler(DrawingAudioData(data)));
}

This is not work. It gives an error that say "Method name expected". What can i do?

Blast
  • 955
  • 1
  • 17
  • 40

1 Answers1

1

Try

public delegate void Draw(byte[] data);

private void myPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    this.Invoke(new Draw(DrawingAudioData), data);
}

Seems to me that the DrawingAudioData passed to Invoke does not have EventHandler signature. Also you should pass the method Name to the delegate constructor.

The DrawingAudioData method should have the signature that matches the Draw delegate:

public void DrawingAudioData(byte[] data) {

More information about Event Handler here.

More information about the Delegate and Invoke method here.

Edi
  • 66
  • 4