/// <summary> /// Stops this input device from receiving messages. /// </summary> /// <remarks> /// <para>This method waits for all in-progress input event handlers to finish, and then /// joins (shuts down) the background thread that was created in /// <see cref="StartReceiving"/>. Thus, when this function returns you can be sure that no /// more event handlers will be invoked.</para> /// <para>It is illegal to call this method from an input event handler (ie, from the /// background thread), and doing so throws an exception. If an event handler really needs /// to call this method, consider using BeginInvoke to schedule it on another thread.</para> /// </remarks> /// <exception cref="InvalidOperationException">The device is not open; is not receiving; /// or called from within an event handler (ie, from the background thread).</exception> /// <exception cref="DeviceException">The device cannot start receiving.</exception> public void StopReceiving() { if (isInsideInputHandler) { throw new InvalidOperationException( "Can't call StopReceiving() from inside an input handler."); } lock (this) { CheckReceiving(); CheckReturnCode(Win32API.midiInStop(handle)); clock = null; isReceiving = false; } }