private void OnVideotape(object obj) { //bool saveOnMotion = false; CameraCtrl.OnVideotape(obj); Func <string> createVideoFile = () => { DateTime date = DateTime.Now; String fileName = String.Format("{0}-{1}-{2} {3}-{4}-{5}.avi", date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second); return(fileName); }; //是否开始录像 if (!saveVideoMonitor) { Camera camera = MainWindow.CameraWindow.Camera; AviFile.AviManager aviManager = new AviFile.AviManager(VideoPath + createVideoFile(), false); double rate = videoRecRate == 0 ? 5.0 : videoRecRate; camera.Lock(); AviFile.VideoStream aviStream = aviManager.AddVideoStream(false, rate, camera.LastFrame); camera.Unlock(); Thread videoRecordThread; Action startVideoRecoder = () => { videoRecordThread = new Thread(() => { Camera _camera = MainWindow.CameraWindow.Camera; while (true) { try { _camera.Lock(); aviStream.AddFrame(MainWindow.CameraWindow.Camera.LastFrame); _camera.Unlock(); Thread.Sleep(500); } catch (Exception) { } } if (aviManager != null) { aviManager.Close(); } videoRecordThread.Abort(); }); videoRecordThread.IsBackground = true; videoRecordThread.Start(); }; saveVideoMonitor = true; } /* * 录像功能 */ //if (!saveOnMotion) //{ // if (dlg.ShowDialog() == DialogResult.OK) // { // Camera camera = cameraWindow.Camera; // aviManager = new AviManager(VideoPath + CreateVideoFile(), false); // double Rate = dlg.Rate == 0.0 ? videoRecRate : dlg.Rate; // camera.Lock(); // aviStream = aviManager.AddVideoStream(false, Rate, camera.LastFrame); // camera.Unlock(); // StartVideoRecorder(); // saveOnMotion = true; // } //} //else //{ // saveOnMotion = false; //} }