471,343 Members | 1,166 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,343 software developers and data experts.

Object type cannot be converted to target type.

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 } );
}
Nov 16 '05 #1
2 5193
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 } } );

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl

Nov 16 '05 #2
Thanks very much
"Wilco Bauwer" <wi****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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 } } );

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Michael Stahl | last post: by
3 posts views Thread by news.microsoft.com | last post: by
5 posts views Thread by Martin Robins | last post: by
16 posts views Thread by anonymous.user0 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.