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 Connect(Loop loop, string name, bool interProcessCommunication, Action<Exception, Pipe> callback) { Ensure.ArgumentNotNull(loop, "loop"); Ensure.ArgumentNotNull(name, "name"); Ensure.ArgumentNotNull(callback, "callback"); ConnectRequest cpr = new ConnectRequest(); Pipe pipe = new Pipe(loop, interProcessCommunication); cpr.Callback = (status, cpr2) => { if (status == 0) { callback(null, pipe); } else { pipe.Close(); callback(Ensure.Success(loop, name), null); } }; uv_pipe_connect(cpr.Handle, pipe.handle, name, ConnectRequest.StaticEnd); }
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()); } }); }
public static void Main(string[] args) { var stdin = new Pipe(); stdin.Open((IntPtr)0); Loop.Default.Run(MainAsync); }