은 내가이 인터페이스를 구현하는 객체 제공 필요로하는 라이브러리를 사용하고 있음을 메모리 스트림에서 :인가 거기에 파일 스트림과 같은 블록
public interface IConsole {
TextWriter StandardInput { get; }
TextReader StandardOutput { get; }
TextReader StandardError { get; }
}
개체의 독자는 다음 라이브러리에 의해 익숙해를 :
IConsole console = new MyConsole();
int readBytes = console.StandardOutput.Read(buffer, 0, buffer.Length);
일반적으로 IConsole을 구현하는 클래스는 외부 프로세스에서 온 것으로 StandardOutput 스트림을 가지고 있습니다. 이 경우 console.StandardOutput.Read 호출은 StandardOutput 스트림에 기록 된 데이터가있을 때까지 블로킹하여 작동합니다.
내가하려고하는 것은 MemoryStreams를 사용하는 Test IConsole 구현을 만들고 StandardInput에 StandardInput에 나타나는 모든 것을 echo하는 것입니다. 나는 시도 :
MemoryStream echoOutStream = new MemoryStream();
StandardOutput = new StreamReader(echoOutStream);
그러나 문제는 일부 데이터가 될 때까지 console.StandardOutput.Read 블록보다는 0을 반환합니다. 어쨌든 사용할 수있는 데이터가 없거나 사용할 수있는 메모리 스트림이 다른 경우 차단할 MemoryStream을 얻을 수 있습니까?
출력 스트림에서 실제로 읽지 않아야합니다. –