Hi,
I purchased the AlterNET
components and we have a need to execute multiple C# scripts from multiple threads. Can the AlterNET Scripter engine execute multiple scripts from different threads and also access share application-defined objects
safely?
Thanks
Hi,
This should be possible, please take a look at Threading Scripter quick start project.
In this sample scripts are executed in parallel tasks, and render on the panel objects which are registered in the script.
If you need to create threads explicitly, you can just use ScriptRun.Run method inside thread execution. In order to access application objects in a thread-safe way you might need to synchronize these calls so they're performed in a main application thread with the code like this:
SynchronizationContext.Current.Send((SendOrPostCallback)(o => MyCode()), null)
You can read a bit more information about SynchronizationContext here.
https://stackoverflow.com/questions/21778078/what-are-difference-between-use-invoke-and-synchronizationcontext-post-object
Let me know if it helps.
Regards,
Andrew
This should be possible, please take a look at Threading Scripter quick start project.
In this sample scripts are executed in parallel tasks, and render on the panel objects which are registered in the script.
If you need to create threads explicitly, you can just use ScriptRun.Run method inside thread execution. In order to access application objects in a thread-safe way you might need to synchronize these calls so they're performed in a main application thread with the code like this:
SynchronizationContext.Current.Send((SendOrPostCallback)(o => MyCode()), null)
You can read a bit more information about SynchronizationContext here.
https://stackoverflow.com/questions/21778078/what-are-difference-between-use-invoke-and-synchronizationcontext-post-object
Let me know if it helps.
Regards,
Andrew
Thank you for the quick reply.