/* Close the device */ public void Close() { /* Notify that ImageProvider is about to close the device to give other objects the chance to do clean up operations. */ OnDeviceClosingEvent(); /* Try to close everything even if exceptions occur. Keep the last exception to throw when it is done. */ Exception lastException = null; /* Reset the removed flag. */ m_removed = false; if (m_hGrabber.IsValid) { /* Try to close the stream grabber. */ try { Pylon.StreamGrabberClose(m_hGrabber); } catch (Exception e) { lastException = e; UpdateLastError(); } } if (m_hDevice.IsValid) { /* Try to deregister the removal callback. */ try { if (m_hRemovalCallback.IsValid) { Pylon.DeviceDeregisterRemovalCallback(m_hDevice, m_hRemovalCallback); } } catch (Exception e) { lastException = e; UpdateLastError(); } /* Try to close the device. */ try { /* ... Close and release the pylon device. */ if (Pylon.DeviceIsOpen(m_hDevice)) { Pylon.DeviceClose(m_hDevice); } } catch (Exception e) { lastException = e; UpdateLastError(); } /* Try to destroy the device. */ try { Pylon.DestroyDevice(m_hDevice); } catch (Exception e) { lastException = e; UpdateLastError(); } } m_hGrabber.SetInvalid(); m_hRemovalCallback.SetInvalid(); m_hDevice.SetInvalid(); /* Notify that ImageProvider is now closed.*/ OnDeviceClosedEvent(); /* If an exception occurred throw it. */ if (lastException != null) { throw lastException; } }