public static IPingPongRunner GetPingPongRunner(PingPongImplementation type) { IPingPongRunner runner = null; switch (type) { case PingPongImplementation.StandaloneThreads: runner = new PingPongViaStandaloneThreads(); break; case PingPongImplementation.ThreadPoolBased: runner = new PingPongViaThreadPool(); break; } return(runner); }
static void Main(string[] args) { PrintWelcome(); String commandStr; do { Console.WriteLine(@" Please enter one of following commands: 0 - Ping-pong implemented via standalone threads 1 - Ping-pong implemented via thread pool exit - exit the program "); commandStr = Console.ReadLine(); IPingPongRunner pingPong = null; PingPongImplementation type; if (Enum.TryParse(commandStr, true, out type)) { pingPong = PingPongFactory.GetPingPongRunner(type); } if (pingPong != null) { var timer = new System.Timers.Timer { Interval = 5000, AutoReset = false, Enabled = true }; timer.Elapsed += (sender, e) => pingPong.Stop(); pingPong.Start(); } } while (!"exit".Equals(commandStr, StringComparison.InvariantCultureIgnoreCase)); }