By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,053 Members | 922 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,053 IT Pros & Developers. It's quick & easy.

Object type cannot be converted to target type.

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.