Object type cannot be converted to target type.

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 } );
}
 
W

Wilco Bauwer

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 } } );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top