private static void GetIndexedEventsPromise() { var feed = DXFeed.GetInstance(); var tsPromise = feed.GetIndexedEventsPromise <IDxTimeAndSale>("IBM", IndexedEventSource.DEFAULT, new CancellationTokenSource(TimeSpan.FromSeconds(2)).Token); Console.WriteLine("TimeAndSale events:"); try { foreach (var result in tsPromise.Result) { Console.WriteLine(result); } } catch (AggregateException ae) { foreach (var exc in ae.InnerExceptions) { if (exc is OperationCanceledException) { Console.WriteLine("not found"); } else { Console.WriteLine(exc); } } } var orderPromise = feed.GetIndexedEventsPromise <IDxOrder>("IBM", OrderSource.NTV, new CancellationTokenSource(TimeSpan.FromSeconds(2)).Token); Console.WriteLine("Order#NTV events:"); try { foreach (var result in orderPromise.Result) { Console.WriteLine(result); } } catch (AggregateException ae) { foreach (var exc in ae.InnerExceptions) { if (exc is OperationCanceledException) { Console.WriteLine("not found"); } else { Console.WriteLine(exc); } } } }
private static void GetLastEventPromisesSample() { string[] symbols = { "C", "IBM", "MSFT" }; var feed = DXFeed.GetInstance(); var promises = feed.GetLastEventsPromises <IDxTrade>( symbols, new CancellationTokenSource(TimeSpan.FromSeconds(5)).Token); // combine the list of promises into one with Task utility method and wait try { Task.WaitAll(promises.Cast <Task>().ToArray()); } catch (AggregateException ae) { foreach (var exc in ae.InnerExceptions) { if (!(exc is OperationCanceledException)) { Console.WriteLine(exc); } } } // now iterate the promises to retrieve results Console.WriteLine("Last events for {0} symbols:", string.Join(", ", symbols)); foreach (var promise in promises) { // result received exceptionally if this event was not found // so first check that task completes successfully if (promise.Status == TaskStatus.RanToCompletion) { Console.WriteLine(promise.Result); } else { Console.WriteLine("not found"); } } }