Open commonsuppliz opened 7 years ago
Handling multiple threads would be an interesting topic. It's important to understand that a runtime can only live on one thread at a time (see rental-threading). So in order to switch a runtime from thread A to thread B, you need to give up the runtime on thread A,
// on thread A JsSetCurrentContext(nullptr);
// on thread B JsSetCurrentContext(context1);
Do You means generated JS Objects wll adhere to one thread (Context), and can not pass across the thread?
No. All your JS objects are adhered to the context they are created on, and you can move context between threads.
https://github.com/Microsoft/ChakraCore/wiki/JavaScript-Runtime-%28JSRT%29-Overview#concepts should give you a good idea about what runtime and context are.
I understand "and you can move context between threads.", and I beg to provide C# code to demonstrate in C# to rental thread context switching.
Is there a particular scenario that you're after? I believe the general idea regardless of language is in https://github.com/Microsoft/Chakra-Samples/issues/78#issuecomment-297580357.
I need to access chakraCore in different thread out of owner context thread (ex. background). Current existing sample in C# is just in one thread. I need sample code to work in multi-thread chakraCore.