I use the built-in functions to avoid excessive garbage collection, especially when working with longer operating modes. Say you would like to receive 2 years or market data for a given ticker symbol. In addition, you can put together a lot of functionality and business logic, if necessary.
what he does is open a socket connection to the server and iterate over the data binding the event to the event. You can think of it the same way as for the class, only one does not write helper methods all over the place that really work only for one functionality. the following is an example of how this might look, note that I am using variables, and the methods of the βhelperβ are below. In the end, I beautifully remove event handlers, if my Exchange class is external / injected, I would not have a registered event handler
void List<HistoricalData> RequestData(Ticker ticker, TimeSpan timeout) { var socket= new Exchange(ticker); bool done=false; socket.OnData += _onData; socket.OnDone += _onDone; var request= NextRequestNr(); var result = new List<HistoricalData>(); var start= DateTime.Now; socket.RequestHistoricalData(requestId:request:days:1); try { while(!done) {
You can see the benefits as indicated below, here you can see an example implementation. Hope this helps explain the benefits.
PPann Aug 22 '18 at 15:33 2018-08-22 15:33
source share