Im using a webcam to show live stream, capture images, record video etc using AForge library.
Each time I get a new frame, I assign it to a pictureBox to show the live stream and i have added a toolstrip for recording video when it is checked. so i did it in the same following method.
private void video_NewFrame( object sender, NewFrameEventArgs eventArgs)
{
// Assigning new frame to a picturebox
pictureBox1.Image = newFrame;
if(recordVideo.Checked)
{
writer.AddFrame(newFrame);
}
}
when the recordVideo toolstrip is checked. I open the avi file
writer.Open("test.avi", pictureBox1.Width, pictureBox1.Height);
and when it is unchecked i close the file.
writer.Close();
but when i start recording the video i get the following error:
InvalidOperationException - object is currently in use elsewhere.