예제 #1
0
        ReadLine(int timeout, string @default)
        {
            using (var process = new System.Diagnostics.Process
            {
                StartInfo =
                {
                    FileName               = "ReadLine.exe",
                    RedirectStandardOutput = true,
                    UseShellExecute        = false
                }
            })
            {
                process.Start();
                var rli = new ReadLineInvoker(process.StandardOutput.ReadLine);
                var iar = rli.BeginInvoke(null, null);

                if (!iar.AsyncWaitHandle.WaitOne(new System.TimeSpan(0, 0, timeout)))
                {
                    process.Kill();
                    return(@default);
                }

                return(rli.EndInvoke(iar));
            }
        }
예제 #2
0
        ReadLine(int timeout, string @default)
        {
            var rli = new ReadLineInvoker(System.Console.ReadLine);
            var iar = rli.BeginInvoke(null, null);

            return(!iar.AsyncWaitHandle.WaitOne(new System.TimeSpan(0, 0, timeout))
             ? @default : rli.EndInvoke(iar));
        }