AForge.Video.MJPEGStream.Stop C# (CSharp) Method

Stop() public method

Stop video source.

Stops video source aborting its thread.

Since the method aborts background thread, its usage is highly not preferred and should be done only if there are no other options. The correct way of stopping camera is signaling it stop and then waiting for background thread's completion.

public Stop ( ) : void
return void
		public void Stop( )
		{
			if ( this.IsRunning )
			{
				stopEvent.Set( );
				thread.Abort( );
				WaitForStop( );
			}
		}

Usage Example

Beispiel #1
0
        public static void VidTest()
        {
            List<Bitmap> frames = new List<Bitmap>();

            AVIWriter aw = new AVIWriter("DIB ");
            aw.FrameRate = 15;
            aw.Open("test2.avi",320,240);
            int i = 0;
            string surl = "";
            MJPEGStream ms = new MJPEGStream();
            ms.Login = "";
            ms.Password = "";
            ms.Source = surl;
            ms.NewFrame += (sender, e) =>
            {
                i++;
                //frames.Add(e.Frame);
                aw.AddFrame(e.Frame);
                e.Frame.Save("test" + i.ToString() + ".jpg", ImageFormat.Jpeg);

            //	            ((MJPEGStream)sender).Stop();
            };

            ms.Start();
            System.Threading.Thread.Sleep(4000);
            ms.Stop();
            aw.Close();

            //
        }