我有folling代码:BackgroundWorker的DisconnectedContext
public static Emgu.CV.Capture _capture;
public static DispatcherTimer _timer;
_timer = new DispatcherTimer();
_timer.Interval = _settings.camera_interval;
_timer.Tick += ProcessFrame;
BacgroundWorker _bw = new BackgroundWorker
{
WorkerReportsProgress = true,
WorkerSupportsCancellation = true
};
_bw.DoWork += (s, e) =>
{
// Initialize the device in background
_capture = new Capture();
};
_bw.RunWorkerCompleted += (s, e) =>
{
_capture.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT,
_settings.camera_height);
_capture.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_WIDTH,
_settings.camera_width);
Brightness = _capture
.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_BRIGHTNESS);
Contrast = _capture
.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_CONTRAST);
// Get images from camera
_timer.Start();
};
_bw.RunWorkerAsync();
public override void CleanUp()
{
_timer.Stop();
_bw.Dispose();
if (_capture != null) _capture.Dispose();
}
应用程序工作正常,但是当我关闭应用程序扔给我:Message: Context0x23754b0' Disconnected. ...
如何解决这个问题?
我忘了清理方法。我会写 – rkmax 2012-07-15 18:51:45
@rkmax,就像一个很好的做法,我会按照与创建相反的顺序处理Dispose,然后尝试显式的Capture.DisposeObject()方法。哦,我会从这些字段中删除'static'修饰符......实际上可能是问题所在。 – 2012-07-15 19:01:54
我试过静态和无静态 – rkmax 2012-07-15 19:04:03