protected override void DisconnectInternal(bool isNormal) { if (_outBuffer != null) { _outBuffer.Dispose(); _outBuffer = null; } if (_inDeviceHandle != IntPtr.Zero) { if (IsConnected) { NativeMethods.midiInStop(_inDeviceHandle); } NativeMethods.midiInClose(_inDeviceHandle); _inDeviceHandle = IntPtr.Zero; _inputClosed.Wait(2500); } if (_outDeviceHandle != IntPtr.Zero) { NativeMethods.midiOutClose(_outDeviceHandle); _outDeviceHandle = IntPtr.Zero; _outputClosed.Wait(2500); } _inputCallback = null; _outputCallback = null; _inDeviceId = 0; _outDeviceId = 0; }