Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With the code below, you are no longer locked during "stage 1" processing:</p> <pre><code>Task.Factory.StartNew(() =&gt; { while (true) { Iterate(); } }, TaskCreationOptions.LongRunning); private void Iterate() { bool marketDataUpdated = false; foreach (Order order in ordersToRegister) { marketDataUpdated = true; // Stage1, Process } foreach (var entry in aggrUpdates) { marketDataUpdated = true; // Stage1, Process } foreach (var entry in commonUpdates) { marketDataUpdated = true; // Stage1, Process } foreach (var entry in infoUpdates) { marketDataUpdated = true; // Stage1, Process } foreach (var entry in tradeUpdates) { marketDataUpdated = true; // Stage1, Process } if (marketDataUpdated) { // Stage2 ! // make a lot of work. expensive operation. recalculate strategies, place orders etc. } } private readonly ConcurrentQueue&lt;Order&gt; ordersToRegister = new ConcurrentQueue&lt;Order&gt;(); private readonly ConcurrentQueue&lt;AggrEntry&gt; aggrUpdates = new ConcurrentQueue&lt;AggrEntry&gt;(); private readonly ConcurrentQueue&lt;CommonEntry&gt; commonUpdates = new ConcurrentQueue&lt;CommonEntry&gt;(); private readonly ConcurrentQueue&lt;InfoEntry&gt; infoUpdates = new ConcurrentQueue&lt;InfoEntry&gt;(); private readonly ConcurrentQueue&lt;TradeEntry&gt; tradeUpdates = new ConcurrentQueue&lt;TradeEntry&gt;(); public void RegistorOrder(object sender, Gate.RegisterOrderArgs e) { ordersToRegister.Enqueue(e.order); } public void TradeUpdated(object sender, Gate.TradeArgs e) { foreach (var entry in e.entries) { tradeUpdates.Enqueue(entry); } } public void InfoUpdated(object sender, Gate.InfoArgs e) { foreach (var entry in e.entries) { infoUpdates.Enqueue(entry); } } public void CommonUpdated(object sender, Gate.CommonArgs e) { foreach (var entry in e.entries) { commonUpdates.Enqueue(entry); } } public void AggrUpdated(object sender, Gate.AggrArgs e) { foreach (var entry in e.entries) { aggrUpdates.Enqueue(entry); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload