-->

Callback Function

2020-02-07 02:44发布

问题:

I have a method called funct which i want to have as my callback function when i am using the beingreceive socket method in c#.

s.BeginReceive(buffer, 0, buffer.Length, System.Net.Sockets.SocketFlags.None,
               new AsyncCallback(funct), null);

The error that am getting is:

No overload for 'funct' matches delegate 'System.AsyncCallback'

What might be the problem here?

回答1:

"funct" must be a method with the following signature:

void funct(IAsyncResult ar) { }


回答2:

You can't just use any method for your callback. The function has to have a specific signature (parameter list).



回答3:

what is the funct? is it a delegate? if it is, it's signature is not compatibile with AsyncCallback delegate.

funct must be a method looking like this:

void SomeMethod(IAsyncResult ar)


回答4:

How does your 'funct' method signature looks like ?

Does it return void ?

Does it have exactly one parameter of type IAsyncResult ?

In other words, does your 'funct' method conform to the Asynccallback delegate ?