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) { /* * This works on unix only if .exe files are somehow associated * with /usr/bin/mono. A good way to test it if they are is to * set them to executables (chmod +x Test.exe) and then just * try to run from command line: ./Test.exe * If they execute, this example should work as well */ Loop.Default.Run(async () => { string file = Path.Combine(Directory.GetCurrentDirectory(), "Test.exe"); using (var stdout = new Pipe() { Writeable = true }) using (var process = Process.Spawn(new ProcessOptions() { File = file, Arguments = new string[] { file }, Streams = new UVStream[] { null, stdout }, })) { Console.WriteLine(await stdout.ReadStringAsync()); } }); }