// Dispose(bool disposing) executes in two distinct scenarios. // If disposing equals true, the method has been called directly // or indirectly by a user's code. Managed and unmanaged resources // can be disposed. // If disposing equals false, the method has been called by the // runtime from inside the finalizer and you should not reference // other objects. Only unmanaged resources can be disposed. protected virtual void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!FDisposed) { if (disposing) { // Dispose managed resources. FSensor = null; FKeyboard = null; if (FDevice != null) { FDevice.Disconnect(); } } // Release unmanaged resources. If disposing is false, // only the following code is executed. if (FHost != null) { FHost.Log(TLogType.Debug, "SpaceMouse is being deleted"); } // Note that this is not thread safe. // Another thread could start disposing the object // after the managed resources are disposed, // but before the disposed flag is set to true. // If thread safety is necessary, it must be // implemented by the client. } FDisposed = true; }
public SpaceMousePlugin() { try { FDevice = new TDx.TDxInput.Device(); FSensor = FDevice.Sensor; FKeyboard = FDevice.Keyboard; // Add the event handlers FDevice.DeviceChange += new TDx.TDxInput._ISimpleDeviceEvents_DeviceChangeEventHandler(DeviceChange); //Connect everything up FDevice.Connect(); } catch (COMException e) { Console.Error.WriteLine("SpaceMouse: " + e.Message); } }