我有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