Original Post
Hi! It's my first attempt to threading. I've got class Tracker that's constantly running in the background using BackgroundWorker. When it is cancelled I need to free a resource, but I've got problems with that. Here's my code: The "cancel" member is set to true in RunWorkerCompleted event handler. The problem is that cap.Close(); is not called, when exiting the app. Where should it, so it would be executed when I exit my app? Thanks in advance
class Tracker
{
public void Run(object data)
{
try
{
cancel = false;
BackgroundWorker bgWorker = null;
if (data != null)
{
bgWorker = (BackgroundWorker)data;
}
cap = new CvCapture(-1, false);
for (; ; )
{
if (cancel == true) break;
Thread.Sleep(1000);
bgWorker.ReportProgress(0, new PointF(1.0f, 1.0f));
}
cap.Close(); // This line is never executed
}
}
}