public override void Call(Dictionary <string, object> context) { Thread.Sleep(5000); // pretend that this is a time consuming task.. File.WriteAllText("result.txt", context["input"].ToString()); Console.WriteLine("result file created.."); Next?.Call(context); }
public override void Call(Dictionary <string, object> context) { // CancellationToken is the idiomatic way of cancelling a Task in C#. CancellationTokenSource source = new CancellationTokenSource(); Logger l = new Logger(source.Token); // start async logging task (providing async context for it).. // if we are inside an async method then we just need to call l.DoLog() directyle. Task.Run(async() => l.DoLog()); try { Next?.Call(context); Thread.Sleep(2000); // wait for another 2 second before we cancel the logging task.. } finally { // the finally block is important to make sure we cancel any running Task even if Next.Call() throws exception source.Cancel(false); } }
public override void Call(Dictionary <string, object> context) { Console.WriteLine("before calling next Call()"); Next?.Call(context); Console.WriteLine("after calling next Call()"); }
public override void Call(Dictionary <string, object> context) { File.WriteAllText("result.txt", context["input"].ToString()); Console.WriteLine("result file created.."); Next?.Call(context); }
public override void Call(Dictionary <string, object> context) { context["input"] = context["input"].ToString().ToUpper(); Next?.Call(context); }