Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is an approach that might be more portable. Hope it helps.</p> <pre><code>public class SafeQueue&lt;T&gt; : Queue&lt;T&gt; { public T SafeDequeue() { lock (this) { return (Count &gt; 0) ? Dequeue() : null; } } public void SafeEnqueue(T entry) { lock (this) { Enqueue(entry); } } } Task.Factory.StartNew(() =&gt; { while (true) { Iterate(); } }, TaskCreationOptions.LongRunning); private void Iterate() { bool marketDataUpdated = false; while ((Order order = ordersToRegister.SafeDequeue()) != null) { marketDataUpdated = true; // Stage1, Process } while ((var entry = aggrUpdates.SafeDequeue()) != null) { marketDataUpdated = true; // Stage1, Process } while ((var entry = commonUpdates.SafeDequeue()) != null) { marketDataUpdated = true; // Stage1, Process } while ((var entry = infoUpdates.SafeDequeue()) != null) { marketDataUpdated = true; // Stage1, Process } while ((var entry = tradeUpdates.SafeDequeue()) != null) { marketDataUpdated = true; // Stage1, Process } if (marketDataUpdated) { // Stage2 ! // make a lot of work. expensive operation. recalculate strategies, place orders etc. } } private readonly SafeQueue&lt;Order&gt; ordersToRegister = new SafeQueue&lt;Order&gt;(); private readonly SafeQueue&lt;AggrEntry&gt; aggrUpdates = new SafeQueue&lt;AggrEntry&gt;(); private readonly SafeQueue&lt;CommonEntry&gt; commonUpdates = new SafeQueue&lt;CommonEntry&gt;(); private readonly SafeQueue&lt;InfoEntry&gt; infoUpdates = new SafeQueue&lt;InfoEntry&gt;(); private readonly SafeQueue&lt;TradeEntry&gt; tradeUpdates = new SafeQueue&lt;TradeEntry&gt;(); public void RegistorOrder(object sender, Gate.RegisterOrderArgs e) { ordersToRegister.SafeEnqueue(e.order); } public void TradeUpdated(object sender, Gate.TradeArgs e) { foreach (var entry in e.entries) { tradeUpdates.SafeEnqueue(entry); } } public void InfoUpdated(object sender, Gate.InfoArgs e) { foreach (var entry in e.entries) { infoUpdates.SafeEnqueue(entry); } } public void CommonUpdated(object sender, Gate.CommonArgs e) { foreach (var entry in e.entries) { commonUpdates.SafeEnqueue(entry); } } public void AggrUpdated(object sender, Gate.AggrArgs e) { foreach (var entry in e.entries) { aggrUpdates.SafeEnqueue(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.
    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