public static void Main(string[] args) { var stdin = new Pipe(); stdin.Open(0); stdin.Read(Encoding.ASCII, (str) => { str = str.TrimEnd(new char[] { '\r', '\n' }); if (str.StartsWith("fib ")) { int n; if (!int.TryParse(str.Substring("fib ".Length), out n)) { Console.WriteLine("Supply an integer to the fib command"); return; } TimeSpan span = TimeSpan.Zero; BigInteger res = 0; Loop.Default.QueueUserWorkItem(() => { var now = DateTime.Now; res = Fibonacci(n); span = DateTime.Now - now; }, () => { Console.WriteLine("{0}: fib({1}) = {2}", span, n, res); }); } else if (str == "quit") { stdin.Close(); } else if (str == "help") { Console.WriteLine("Available commands: "); Console.WriteLine("fib <n:int> - start a thread which calculates fib"); Console.WriteLine("help - displays help"); Console.WriteLine("quit - quits the program"); } else { Console.WriteLine("Unknown command"); } }); stdin.Resume(); Loop.Default.Run(); }
public static async Task MainAsync() { var stdin = new Pipe(); stdin.Open((IntPtr)0); string str = null; while ((str = await stdin.ReadStringAsync()) != null) { str = str.TrimEnd(new char[] { '\r', '\n' }); if (str.StartsWith("fib ")) { int n; if (!int.TryParse(str.Substring("fib ".Length), out n)) { Console.WriteLine("Supply an integer to the fib command"); return; } TimeSpan span = TimeSpan.Zero; BigInteger res = 0; Loop.Default.QueueUserWorkItem(() => { var now = DateTime.Now; res = Fibonacci(n); span = DateTime.Now - now; }, () => { Console.WriteLine("{0}: fib({1}) = {2}", span, n, res); }); } else if (str == "quit") { break; } else if (str == "help") { Console.WriteLine("Available commands: "); Console.WriteLine("fib <n:int> - start a thread which calculates fib"); Console.WriteLine("help - displays help"); Console.WriteLine("quit - quits the program"); } else { Console.WriteLine("Unknown command"); } } stdin.Shutdown(); }
public static void Main(string[] args) { var stdin = new Pipe(); stdin.Open((IntPtr)0); Loop.Default.Run(async delegate { await MainAsync(); }); }
public static void Main(string[] args) { var stdin = new Pipe(); stdin.Open((IntPtr)0); Loop.Default.Run(MainAsync); }