W
WildHare
I have a generalized CreateThread method which is passed an object (e.g.
CreateThread( object objIn ) ). The object that I am passing are
instantiations of one of several different classes all of which contain an
execute method ( execute() ). We don't know until the CreateThread method
is called which type of object will be passed.
Inside the CreateThread method we get to the usual:
Thread cThread = new Thread( new ThreadStart( objIn.execute ));
Which, of course doesn't work because something of type "object" (the type
indicated in the parameter list) does not contain the execute() method.
I can cast objIn by writing:
Thread cThread = new Thread( new ThreadStart( (ClassName)objIn.execute ));
// and this works
but that suggests that I know what ClassName is when I write the
code...which I don't.
I have tried several variants of objIn.GetType(), etc...and I can't make it
work. I suspect it is something like that, but I can't get it.
Any suggestions are welcome.
CreateThread( object objIn ) ). The object that I am passing are
instantiations of one of several different classes all of which contain an
execute method ( execute() ). We don't know until the CreateThread method
is called which type of object will be passed.
Inside the CreateThread method we get to the usual:
Thread cThread = new Thread( new ThreadStart( objIn.execute ));
Which, of course doesn't work because something of type "object" (the type
indicated in the parameter list) does not contain the execute() method.
I can cast objIn by writing:
Thread cThread = new Thread( new ThreadStart( (ClassName)objIn.execute ));
// and this works
but that suggests that I know what ClassName is when I write the
code...which I don't.
I have tried several variants of objIn.GetType(), etc...and I can't make it
work. I suspect it is something like that, but I can't get it.
Any suggestions are welcome.