Accord.DirectSound.WaveFileAudioSource.WorkerThread C# (CSharp) Method

WorkerThread() private method

Worker thread.
private WorkerThread ( ) : void
return void
        private void WorkerThread()
        {
            SoundStream waveStream = null;

            try
            {
                waveStream = (stream != null)
                    ? new SoundStream(stream)
                    : new SoundStream(File.OpenRead(fileName));

                // Open the Wave stream
                decoder.Open(waveStream);

                while (stopEvent.WaitOne(0, false))
                {
                    // get next frame
                    Signal s = decoder.Decode(frameSize);
                    framesReceived += s.Length;
                    bytesReceived += decoder.Bytes;

                    if (NewFrame != null)
                        NewFrame(this, new NewFrameEventArgs(s));

                    // check current position
                    if (waveStream.Position >= waveStream.Length)
                        break;

                    // sleeping ...
                    Thread.Sleep(100);
                }
            }
            catch (Exception exception)
            {
                // provide information to clients
                if (AudioSourceError != null)
                {
                    AudioSourceError(this, new AudioSourceErrorEventArgs(exception.Message));
                }
                else
                {
                    throw;
                }
            }

            if (waveStream != null)
            {
                waveStream.Close();
                waveStream.Dispose();
                waveStream = null;
            }
        }