KekoSha
KekoSha

Reputation: 125

No Overload for '' match delegate 'System.EventHandler'

There is error about

ParameterizedThreadStart op = new ParameterizedThreadStart(new EventHandler(this.SendResultToClient));

No Overload for 'SendResultToClient' match delegeate 'System.EventHandler'

any help

 public void Add(double num)
   {
    double result = (num+10);
             //Gets a channel to the client instance that called the current operation.
            callback = OperationContext.Current.GetCallbackChannel<IAddNumDuplexCallback>();
            //Represents the method that executes on a Thread.
            ParameterizedThreadStart op = new ParameterizedThreadStart(new EventHandler(this.SendResultToClient));
            Thread t = new Thread(op);
             //t.IsBackground = true;
             t.Start(result);
         }

        //The function
        public void SendResultToClient(double result)
        {
          Thread.Sleep(500);
          callback.Result(result);
        }
   }
}

Upvotes: 0

Views: 1249

Answers (1)

Alberto
Alberto

Reputation: 15951

You are using ParameterizedThreadStart in the wrong way.

ParameterizedThreadStart is a delegate for a method that accepts one argument of type object and returns void.

You need to change your SendResultToClient method in:

public void SendResultToClient(object data)
{
    double result = (double)data;
    Thread.Sleep(500);
    callback.Result(result);
}

and start the thread in this way:

ParameterizedThreadStart op = SendResultToClient;
Thread t = new Thread(op);
t.Start(result);

Upvotes: 2

Related Questions