title: Implement custom stream
body: <p>I am calling a dll that writes to a stream. The signature of the method in the dll looks like:</p>
  
  <pre><code>public bool SomeMethod(Stream stream);
  </code></pre>
  
  <p>and that method will basically write binary data to that stream. So if I will call that method as:</p>
  
  <pre><code>var file = System.IO.File.Create("SomeFile.txt");
  /* call dll method */ SomeMethod(file); 
  </code></pre>
  
  <p>then I will be basically writing the output to that file. In this question I am writing the output to a networkStream.</p>
  
  <p><strong>Anyways so back to the question</strong>. The reason why I will like to create my own stream is because I will like to know when some events take place. For example if I where to create my own stream class as:</p>
  
  <pre><code>class MyStream : Stream
  {
      private long Position;
  
      public override int Read(byte[] buffer, int offset, int count)
      {
  
              // implementation goes here
  
              /* HERE I COULD CALL A CUSTOM EVENT */
      }
  
      public override long Seek(long offset, SeekOrigin origin)
      {
          // SAME THING I WILL LIKE TO PERFORM AN ACTION IF THIS METHOD IS CALLED!
      }
  
      // etc implement rest of abstract methods....
  </code></pre>
  
  <p>I am writing the output of that stream to the network so I might want to slow down if some event occurs. If I where to have control of the dll then I would not be trying to implement this. </p>
  
  <p>I will appreciate if someone could show me a very basic example of how to implement the abstract methods of the abstract Stream Class. </p>