public override void BeforeClose() { if (cameraLoaded) { UnloadCamera(); } if (pipelineManager != null) { // Destroy resources (symmetric to constructor). pipelineManager.FrameSignaled -= pipelineManager_FrameSignaled; pipelineManager = null; } consumerDisplay = null; nonGrabbingInteractionTimer.Stop(); nonGrabbingInteractionTimer.Tick -= NonGrabbingInteractionTimer_Tick; grabTimer.Stop(); grabTimer.Tick -= grabTimer_Tick; viewportController.DisplayRectangleUpdated -= ViewportController_DisplayRectangleUpdated; if (view != null) { view.DualCommandReceived -= OnDualCommandReceived; view.BeforeClose(); view = null; } }
public CaptureScreen() { // There are several nested lifetimes with symetric setup/teardown methods: // Screen -> ctor / BeforeClose. // Camera association -> LoadCamera / UnloadCamera. // Connection (frame grab) -> Connect / Disconnect. // Recording -> StartRecord / StopRecord. log.Debug("Constructing a CaptureScreen."); view = new CaptureScreenView(this); view.DualCommandReceived += OnDualCommandReceived; viewportController = new ViewportController(); viewportController.DisplayRectangleUpdated += ViewportController_DisplayRectangleUpdated; viewportController.Poked += viewportController_Poked; view.SetViewport(viewportController.View); view.SetCapturedFilesView(capturedFiles.View); InitializeCaptureFilenames(); InitializeTools(); InitializeMetadata(); delayCompositer = new DelayCompositer(delayer); delayCompositeConfiguration = PreferencesManager.CapturePreferences.DelayCompositeConfiguration; delayComposite = GetComposite(delayCompositeConfiguration); delayCompositer.SetComposite(delayComposite); view.SetToolbarView(drawingToolbarPresenter.View); IntPtr forceHandleCreation = dummy.Handle; // Needed to show that the main thread "owns" this Control. nonGrabbingInteractionTimer.Interval = 40; nonGrabbingInteractionTimer.Tick += NonGrabbingInteractionTimer_Tick; grabTimer.Tick += grabTimer_Tick; pipelineManager.FrameSignaled += pipelineManager_FrameSignaled; }