PDA

Click to See Complete Forum and Search --> : Using MethodInvoker to pass variables to a method


farklem
Aug 15th, 2005, 12:11 PM
I have been trying to use MethodInvoker to run a method but im not sure how to get the syntax right so it passes a string to the method. As of now I get this error when trying to build: C:\Documents and Settings\Administrator\Desktop\IRCb\frmServer.cs(590): Method 'IRCb.frmServer.RecieveCommand(string)' does not match delegate 'void System.Windows.Forms.MethodInvoker()'


public void RecieveCommand(string Command)
{
Console.WriteLine(Command);
}

public void InvokeRecieve()
{
MethodInvoker MI = new MethodInvoker(RecieveCommand);
this.BeginInvoke(MI);
}


Thanks :)

Mike Hildner
Aug 15th, 2005, 12:49 PM
You can't use parameters with MethodInvoker

MethodInvoker provides a simple delegate that is used to invoke a method with a void parameter list. This delegate can be used when making calls to a control's invoke method, or when you need a simple delegate but don't want to define one yourself.

I think you'll have to make your own delegate.

Mike