[Mono-devel-list] Calling C# delegate from native code on a different thread.
Daniel L. Christensen
dachristensen at gw.novell.com
Wed Jul 14 14:03:16 EDT 2004
I'm trying to wrap a native C++ API with C#. I've run into a spot where
the C# object needs to register for an event that occurs on the native
C++ object. So I pass down a delegate which gets converted to a function
pointer on the native side, wrap the funciton pointers with an event
handler object and register the event handler object with the native C++
object. Certain actions performed by the C++ object happen
asynchronously (i.e. on another thread that mono doesn't know about).
When the action completes (or is in progress) it generates a native
event. The native object calls back on the event handler which in turn
tries to call back up into the C# code using the function pointer that
was created from the delegate. When this happens I get the following
** ERROR **: file mini.c: line 6508 (mono_get_lmf_addr): should not be
I imagine that the problem is that I am trying to communicate to the
mono vm from a thread that is not attached to it. When attempting a
similar operation in Java/JNI, you are required to attach the JVM to the
native thread before trying to call up into java. Does mono have a
similar convention? How is this accomplished? Or, is there a better way
to accomplish this using mono?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Mono-devel-list