There shouldn't be any singletons that would prevent you from multithreading, and on top of that each time your optimization plugin calls RunSystem a separate AppDomain is created for that run, so even if your trading system or one of your plugins used singletons, they would still be isolated from other copies of your system running on other threads.
Hi Daniel, it's a good insight that the calls to RunSystem are executed on different AppDomains, but the problem I have with trying to thread the default Optimization plug-in as an exercise is that I depend on the instance of SystemRunSettings that are passed to the plug-in by RE. SystemRunSettings has no copy constructor, it has no Clone or MemberwiseClone methods. This means that the same instance of SystemRunSettings is passed to every call to RunSystem. Needless to say they all collide when executed simultaneously, so only the last parameters set by runSettings.SystemParameters actually get used for a full optimization run. I see no way of decoupling from this (due to aforementioned lack of methods to create a new instance with all the same properties).
Am I missing some solution, or is it actually impossible to run multiple calls to RunSystem at the same time? The SystemRunSettings type is serializable, so I suppose it is possible to serialize the given instance to a MemoryStream then deserialize into a new instance... but that seem like way to much work just to replicate some properties. Also, I'm not even sure the new instance would be valid, I mean the original SystemRunSettings instance comes from somewhere else in RE, so RE could have other references to it somewhere (or even some internal properties, which I wouldn't see and wouldn't be able to replicate with this method), will my own hacked up copy even work?
Thank you for advice.
Saturday March 26 2011 by