Support Board
Date/Time: Mon, 25 Nov 2024 09:32:26 +0000
Post From: TCP/IP Server in custom study
[2021-06-13 22:11:21] |
User310645 - Posts: 49 |
As I mentioned earlier in point 3), some methods simply don't work unless you call them at the same time that SC is calling into your study. If anyone knows how to get around this please let me know. For your example you could get the SCFloatArray reference of the VWAP study and pass it into the Server class when you construct it rather than calling the GetStudy method from within the thread. (Make sure the custom study is below the vwap study in the chart study list so its initialised first). Server* server = static_cast<Server*>(sc.GetPersistentPointer(1)); if (server == NULL) { SCFloatArray VWAP_Reference; sc.GetStudyArrayUsingID(5, 0, VWAP_Reference); server = new Server(sc, 1, VWAP_Reference); server->Start(); sc.SetPersistentPointer(1, server); } Whilst this should work for your immediate vwap issue, if you have lots of these or other reasons to call into the scinterfaceref it could become unworkable. If you really must call a method on the sc object then you could create a sync point (std::condition_variable) and wait/notify when SC calls into your method although this is pretty pointless as your thread would be waiting you might as well just call it when the study function is called and/or block the main sc thread if you waited until you had finished whatever processing the thread did. Other options could be to populate a data structure in the study function call and then let the thread access it in a producer/consumer kind of way. Lastly, do you really need a background thread at all and could you get away with just pushing the data when it becomes available in the study function call? |