private static void RunConti(string nodeName, Node node) { var cancel = new CancellationTokenSource(); Task.Run(() => { while (true) { cancel.Token.ThrowIfCancellationRequested(); Console.WriteLine("Broadcasting via {0}", nodeName); node.Broadcast("Msg by " + nodeName); Task.Delay(TimeSpan.FromSeconds(1), cancel.Token).Wait(cancel.Token); } }, cancel.Token); Console.ReadLine(); cancel.Cancel(); }
static void Main(string[] args) { var nodeName = args[0]; Console.Title = nodeName; using (var node = new Node(nodeName).Start().Result) { node.Message += msg => Console.WriteLine("{1} got: {0}", msg, nodeName); while (true) { var c = Console.ReadKey(); if (c.KeyChar == 'q') { break; } Console.WriteLine("Broadcast by {0}", nodeName); node.Broadcast("Msg by " + nodeName); } } }