AForge.Video.Ximea.XimeaVideoSource.WorkerThread C# (CSharp) Метод

WorkerThread() приватный Метод

private WorkerThread ( ) : void
Результат void
        private void WorkerThread( )
        {
            ReasonToFinishPlaying reasonToStop = ReasonToFinishPlaying.StoppedByUser;

            try
            {
                camera.StartAcquisition( );

                // while there is no request for stop
                while ( !stopEvent.WaitOne( 0, false ) )
                {
                    // start time
                    DateTime start = DateTime.Now;

                    // get next frame
                    Bitmap bitmap = camera.GetImage( 15000, false );

                    framesReceived++;
                    bytesReceived += bitmap.Width * bitmap.Height * ( Bitmap.GetPixelFormatSize( bitmap.PixelFormat ) >> 3 );

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

                    // free image
                    bitmap.Dispose( );

                    // wait for a while ?
                    if ( frameInterval > 0 )
                    {
                        // get frame duration
                        TimeSpan span = DateTime.Now.Subtract( start );

                        // miliseconds to sleep
                        int msec = frameInterval - (int) span.TotalMilliseconds;

                        if ( ( msec > 0 ) && ( stopEvent.WaitOne( msec, false ) ) )
                            break;
                    }
                }
            }
            catch ( Exception exception )
            {
                reasonToStop = ReasonToFinishPlaying.VideoSourceError;
                // provide information to clients
                if ( VideoSourceError != null )
                {
                    VideoSourceError( this, new VideoSourceErrorEventArgs( exception.Message ) );
                }
            }
            finally
            {
                try
                {
                    camera.StopAcquisition( );
                }
                catch
                {
                }
            }

            if ( PlayingFinished != null )
            {
                PlayingFinished( this, reasonToStop );
            }
        }
    }