private static void PostSomeWorker() { for (int i = 0; i < 100; i++) { var save = i; DisaptcherToken.Post(new Worker(), save); } }
static async Task Execute(string sel, int count) { await Task.Yield(); AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; switch (sel) { case "complete": { //Chain with run CompleteWorker on completed var completedChain = CreateChain(1, count); completedChain.Run(new CompletedWorker()); break; } case "callback": { //Chain with call callback on completed var callbackChain = CreateChain(1, count); callbackChain.Run(p => { //await Task.Yield(); var cpl = new CompletedWorker().Invoke(p, CancellationToken.None); cpl.Wait(); }); break; } case "async": { //Chain with async task var asyncChaing = CreateChain(1, count); await asyncChaing.RunAsync().ContinueWith(t => { if (!t.IsFaulted) { PrintResult(t.Result); } }, TaskContinuationOptions.OnlyOnRanToCompletion); break; } case "sync": { //Chain run synchronous and get result on completed var stopwatch = Stopwatch.StartNew(); var syncChaing = CreateChain(1, count); var res = syncChaing.RunSync(); stopwatch.Stop(); Console.WriteLine($"Total time: {stopwatch.ElapsedMilliseconds}"); PrintResult(res); break; } case "pages": { DisaptcherToken.Post(new FindPagesWorker(DisaptcherToken, new string[] { "https://raw.githubusercontent.com/NemoTravel/nemo.travel.geodata/master/airlines.json", "https://raw.githubusercontent.com/NemoTravel/nemo.travel.geodata/master/countries.json", "https://raw.githubusercontent.com/NemoTravel/nemo.travel.geodata/master/airports.json" })); break; } } }