Unfortunately, the Bueller prompt didn't work for me, because ReadLine might be blocked.
But with Zachβs answer to StreamReader.Peek and Thread.Interrupt Alternative, I came up with the following:
[DllImport("kernel32.dll", SetLastError = true)] static extern bool PeekNamedPipe(SafeHandle handle, byte[] buffer, uint nBufferSize, ref uint bytesRead, ref uint bytesAvail, ref uint BytesLeftThisMessage); static bool SomethingToRead(SafeHandle streamHandle) { byte[] aPeekBuffer = new byte[1]; uint aPeekedBytes = 0; uint aAvailBytes = 0; uint aLeftBytes = 0; bool aPeekedSuccess = PeekNamedPipe( streamHandle, aPeekBuffer, 1, ref aPeekedBytes, ref aAvailBytes, ref aLeftBytes); if (aPeekedSuccess && aPeekBuffer[0] != 0) return true; else return false; }
In my case, an extra P / Invoke call is not a problem.
source share