public Task CloseAsync() { return(Task.Run(() => { lock (lockObject) { Connection = MidiPortConnectionState.Pending; DieOnError(WinMMNatives.midiInReset(handle)); DieOnError(WinMMNatives.midiInStop(handle)); DieOnError(WinMMNatives.midiInClose(handle)); // wait for the device driver to hand back the long buffers through HandleMidiInProc for (int i = 0; i < 1000; i++) { lock (lockObject) { if (lmBuffers.Count < 1) { break; } } Thread.Sleep(10); } Connection = MidiPortConnectionState.Closed; } })); }
public Task CloseAsync() { return(Task.Run(() => { Connection = MidiPortConnectionState.Pending; WinMMNatives.midiInClose(handle); Connection = MidiPortConnectionState.Closed; })); }