Program wont close and aforge camera keeps running, threading trouble

Well I managed to debug the program, and finally found what caused the problem. It is a little bit strange since as a button I could stop the camera using the exitcamera function.

However, inside a _formclosing event the same routine didn't work although it worked after I had marked out the waitforstop function.

 private void exitcamera()
 { 
  FinalVideo.SignalToStop();
  // FinalVideo.WaitForStop();  << marking out that one solved it
  FinalVideo.NewFrame -= new NewFrameEventHandler(FinalVideo_NewFrame); // as sugested
  FinalVideo = null;
 } 

I am still a bit confused about it, why this wont work in case a closing event. But it seems to be solved by this.


Maybe you have memory leaks problems caused by the event. You could try to unhook the event while exiting the programm :

FinalVideo.NewFrame -= new NewFrameEventHandler(FinalVideo_NewFrame);

Maybe this will help.