Object type cannot be converted to target type.

  • Thread starter Thread starter Paul Tomlinson
  • Start date Start date
P

Paul Tomlinson

I am trying to call a delegate on my parent from a child thread, this is my
code, however i'm getting an exception "Object type cannot be converted to
target type." which I can't understand. The prototype for my delegate is:

public delegate void ExceptionDelegate( object[] o ); // called from all
child threads

This is the offending code. Can anyone shed any light please?

if( myParent.InvokeRequired )
{
myParent.Invoke( myParent.MessageOnException, new object[] {
e.Message } );
}
else
{
myParent.MessageOnException( new object[] { e.Message } );
}
 
The second argument of Invoke excepts an array of objects you want to
pass as arguments to the delegate. Your delegate expects 1 argument,
which is of the type object[]. Your code should therefore look
something like the following:

myParent.Invoke( myParent.MessageOnException, new object[] { new
object[] {
e.Message } } );
 
Back
Top