public Task AskProcessor() { if (Token == null) { Token = new CancellationTokenSource(); } AskProcessorTask = Task.Factory.StartNew(() => { while (!Token.IsCancellationRequested) { foreach (var ask in AsksToProcess.ToArray()) { long orderQuantity; if (ask.Value.LockExecuteQuantity == 0) { if (GetQuote(ask.Value, out orderQuantity, maxLegDepth: ask.Value.MaxLegDepth) != null) { ask.Value.RealizeLockExecuteQuantiy(); ExecuteAsk(ask.Value, ask.Value.MaxLegDepth); } else { ask.Value.RealizeLockExecuteQuantiy(); } } ThreadSafeAsk tAsk; AsksToProcess.TryRemove(ask.Key, out tAsk); } if (!Token.IsCancellationRequested) { Task.Delay(10000).Wait(); } } }, Token.Token); return(AskProcessorTask); }
private void ThreadSafeAsk_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { ThreadSafeAsk ask = (ThreadSafeAsk)sender; AsksToProcess.AddOrUpdate(ask.AskID, ask, (k, a) => a); }