private Device(NativeMethods.k4a_device_t handle) { // Hook the native allocator and register this object. // .Dispose() will be called on this object when the allocator is shut down. Allocator.Singleton.RegisterForDisposal(this); this.handle = handle; }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>True</c> to release both managed and unmanaged resources; <c>False</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (!this.disposedValue) { if (disposing) { Allocator.Singleton.UnregisterForDisposal(this); this.handle.Close(); this.handle = null; this.disposedValue = true; } } }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. handle.Close(); handle = null; disposedValue = true; } }
/// <summary> /// Opens an Azure Kinect device. /// </summary> /// <param name="index">Index of the device to open if there are multiple connected.</param> /// <returns>A Device object representing that device.</returns> /// <remarks>The device will remain opened for exclusive access until the Device object is disposed.</remarks> public static Device Open(int index = 0) { NativeMethods.k4a_device_t handle = default; AzureKinectOpenDeviceException.ThrowIfNotSuccess(() => NativeMethods.k4a_device_open((uint)index, out handle)); return(new Device(handle)); }
private Device(NativeMethods.k4a_device_t handle) { this.handle = handle; }