程序不关闭和aforge相机保持运行,线程的麻烦 [英] Program wont close and aforge camera keeps running, threading trouble

查看:1389
本文介绍了程序不关闭和aforge相机保持运行,线程的麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一点奇怪的问题,我觉得这很难调试
有时我cannt关闭了一个程序,它冻结当我试图将其关闭
我犯了一个大程序的视频图像识别,它工程
我做了一个特殊的按钮,关闭相机
此按钮,这个工程由下面调用一个函数,它的确,它的工作。

I have a bit strange problem, which i find hard to debug Sometimes i cannt close my program and it freezes when i try to close it I made a large program for video image recognition, it works I made a special button to close the camera This button works with this by calling a function below, and it indeed, it does work.

 private void exitcamera()
 { 
 FinalVideo.SignalToStop();
 FinalVideo.WaitForStop();
 FinalVideo = null;
 }



注意,原始视频开始像这样

Notice that the original video was started like this

 private void buttonStartCamera_Click(object sender, EventArgs e) 
 {
 FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[comboBox1.SelectedIndex].MonikerString);
 FinalVideo.DesiredFrameSize = new System.Drawing.Size(640, 480);
 FinalVideo.DesiredFrameRate = 90;
 FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
 FinalVideo.ProvideSnapshots = true;  //snapshots
 FinalVideo.Start(); 
 }

现在我的问题接缝(这是一种猜测,因为我cannt调试这一刻)
即某个线程仍然活跃想要更新数据的主要形式。
然而,它可能无法这样做,因为一个正在缩小。
我觉得这样的事情是怎么回事,所以我写的主要应用形式

Now my problem seams (and this is a guess because i cannt debug this moment) That some thread is still active wanting to update the main form with data. However it might not be able to do so since that one is closing. I think something like that is going on so i wrote on the main application form

    private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
     // Thread.Sleep(1000); // not sure about these delays might help syncing threads
     ExitCamera();
     Thread.Sleep(1000);
    }

然而,在地方去年代码程序有更多的麻烦要退出吗?

However with that last code in place the program has even more trouble to exit ?

我想送的子线程退出,但我不知道他们的名字(如果他们有一个名字),我不知道如何将它们列或指导他们停止他们在另一个DLL不是我的代码的一部分。一些DLL的我没有代码。

I would like to send the subthreads an exit, but i dont know their names (if they have a name), I dont know how to list them or to instruct them to stop they are in another dll not my part of the code. from some dll's i dont have the code.

那么,有没有挂牌子线程的方式,然后关闭它们一个接一个,如果按下uppercorner右路传中退出应用?

So are there ways of listing sub threads and then close them one by one, if one presses the uppercorner right cross to exit the application ?

推荐答案

嗯,我设法调试程序,最后发现是什么原因造成的问题。
这是一个有点怪,因为作为一个按钮,我可以使用exitcamera功能停止摄像。

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.

不过,_formclosing事件中相同的程序没有工作
虽然它的工作我已经标示出waitforstop功能之后。

However, inside a _formclosing event the same routine didnt 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 seams to be solved by this.

这篇关于程序不关闭和aforge相机保持运行,线程的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆