/// <summary> /// Thread method for managing headers. /// </summary> private void ManageHeaders() { // While the device is open. while (IsOpen()) { // Wait to be signalled when a header had finished being used. resetEvent.WaitOne(); // While there are still headers in the queue. while (syncHeaderQueue.Count > 0) { // Get header from the front of the queue. MidiHeader header = (MidiHeader)syncHeaderQueue.Dequeue(); // Unprepare header. int result = midiOutUnprepareHeader(handle, ref header, Marshal.SizeOf(header)); // If an error occurred with unpreparing the system // exclusive header. if (result != MMSYSERR_NOERROR) { if (SysExHeaderErrorOccurred != null) { OutputDeviceException ex = new OutputDeviceException(result); SysExHeaderErrorOccurred(this, new SysExHeaderErrorEventArgs(ex.Message)); } } // Free memory allocated for the system exclusive data. Marshal.FreeHGlobal(header.data); } } }
/// <summary> /// Thread method for managing headers. /// </summary> private void ManageHeaders() { // While the device is open. while(IsOpen()) { // Wait to be signalled when a header had finished being used. resetEvent.WaitOne(); // While there are still headers in the queue. while(syncHeaderQueue.Count > 0) { // Get header from the front of the queue. MidiHeader header = (MidiHeader)syncHeaderQueue.Dequeue(); // Unprepare header. int result = midiOutUnprepareHeader(handle, ref header, Marshal.SizeOf(header)); // If an error occurred with unpreparing the system // exclusive header. if(result != MMSYSERR_NOERROR) { if(SysExHeaderErrorOccurred != null) { OutputDeviceException ex = new OutputDeviceException(result); SysExHeaderErrorOccurred(this, new SysExHeaderErrorEventArgs(ex.Message)); } } // Free memory allocated for the system exclusive data. Marshal.FreeHGlobal(header.data); } } }