title: Writing on a stream while it is processed by a speech recognition engine
body: <p>I'm using C# and .Net 4.5</p>
  
  <p>I have a MemoryStream which I gave to the Microsoft Speech Recognition Engine, but if fails to recognize the stream.</p>
  
  <p>The problem is that the stream is written by another Thread while the speech recognition accesses it, since I handed a Stream.synchronized(stream) object to the speech recognition the access itself is not the problem, it is thread-safe.
  I think there is a problem with the position pointer. The pointer is, of course, at the end of the newly written data which thread 1 wrote onto the stream. So thread 1 always writes and pushes the pointer to the end and the result is that the pointer points always to the last element within the stream.
  The recognition engine, thread 2, thinks there is nothing new to read since the pointer is at the end.</p>
  
  <p>The only solution can image is to write a new class derived from the stream class which has two separate position pointers. One for the writing and one for the reading.</p>
  
  <p>Is there any other solution?</p>
  
  <p>Regards,</p>
  
  <p>Max</p>
  
  <p>Edit: Some Code:</p>
  
  <p>(Sre Thread)</p>
  
  <pre><code>SpeechAudioFormatInfo info = new SpeechAudioFormatInfo(16000, AudioBitsPerSample.Sixteen, AudioChannel.Mono);
  sre.SetInputToAudioStream(stream, info);
  sre.RecognizeAsync(RecognizeMode.Multiple);
  </code></pre>
  
  <p>(UDP Thread)</p>
  
  <pre><code>test.Write(messagePart, 0, messagePart.Length);
          test.Flush();
  </code></pre>