Hi i’m using Embedded Mono with NaCl. Everything is working so far but idk how to invoke a .NET method from c thats not on the same thread as the .NET exe was executed on.
Here is the method i’m trying to use:
void Mono_InvokeMethod(const char* assemblyName, const char* method, const char* arg)
{
MonoAssemblyName* man = mono_assembly_name_new(assemblyName);
assert(man);
MonoAssembly* ma = mono_assembly_loaded(man);
assert(ma);
MonoImage* mi = mono_assembly_get_image(ma);
assert(mi);
MonoMethodDesc* mmd = mono_method_desc_new(method, "Second.Program" /* include_namespace */);
assert(mmd);
MonoMethod* mm = mono_method_desc_search_in_image(mmd, mi);
assert(mm);
void *args[1];
args[0] = mono_string_new(mono_get_domain(), arg);//mono_get_root_domain() <<<<<<< Maybe use this instead
mono_runtime_invoke(mm, NULL /* "this" object */, args, NULL /* exception */);
}
You must start the new thread yourself and then call
mono_thread_attachbeforemono_runtime_invoke. This is how it would look like, assumingthread_callbackis called on a separate thread:You can call
mono_thread_attachas many times as you want, you don’t have to keep track of whether you’ve called it for a particular thread or not.