Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems that there is no implementation of this - which is strange, since I agree that it would be a useful construct. But it should be simple to write. Something like this should work:</p> <pre><code> public class BlockingStream: Stream { private readonly Stream _stream; public BlockingStream(Stream stream) { if(!stream.CanSeek) throw new ArgumentException("Stream must support seek", "stream"); _stream = stream; } public override void Flush() { lock (_stream) { _stream.Flush(); Monitor.Pulse(_stream); } } public override long Seek(long offset, SeekOrigin origin) { lock (_stream) { long res = _stream.Seek(offset, origin); Monitor.Pulse(_stream); return res; } } public override void SetLength(long value) { lock (_stream) { _stream.SetLength(value); Monitor.Pulse(_stream); } } public override int Read(byte[] buffer, int offset, int count) { lock (_stream) { do { int read = _stream.Read(buffer, offset, count); if (read &gt; 0) return read; Monitor.Wait(_stream); } while (true); } } public override void Write(byte[] buffer, int offset, int count) { lock (_stream) { long currentPosition = _stream.Position; _stream.Position = _stream.Length; _stream.Write(buffer, offset, count); _stream.Position = currentPosition; Monitor.Pulse(_stream); } } public override bool CanRead { get { lock (_stream) { return _stream.CanRead; } } } public override bool CanSeek { get { lock (_stream) { return _stream.CanSeek; } } } public override bool CanWrite { get { lock (_stream) { return _stream.CanWrite; } } } public override long Length { get { lock (_stream) { return _stream.Length; } } } public override long Position { get { lock (_stream) { return _stream.Position; } } set { lock (_stream) { _stream.Position = value; Monitor.Pulse(_stream); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload