المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to stop an Event



C# Programming
05-14-2009, 12:30 AM
Hi,
I'm using C#.net 3.0 to develop an application on digital watermarking.I'm using FrameGrabber class which I have found on this site.What the class is doing-it is getting the constituent frames in the Bitmap format (*.bmp) from the given video file.Now the problem is that there is no way to stop the function in the middle of execution i.e. if I want to stop the function from extracting further more frames I have to shutdown the application.Now I want to put a function on Button(STOP) such that when I press the button it will stop the function from further execution and all the frames so far extracted should remain in the destined folder.Can anybody please tell me how to do this.

This is the code for Button- Extact frames


private void button43_Click(object sender, EventArgs e)//to extract frame
{
string outPath = txtExtBitmap.Text;//path of destination folder where the extracted frames are kept
System.IO.Directory.CreateDirectory(outPath);

if (fg != null)
{
foreach (FrameGrabber.Frame f in fg)
{
using (f)
{
picBoxFrame.Image = (Bitmap)f.Image.Clone();
f.Image.Save(System.IO.Path.Combine(outPath, "frame" + f.FrameIndex + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);//save each frame in *.bmp format
Application.DoEvents();
}

if (fg == null)
{
return;
}
}
}



Thank You!!