// TODO: is cleaning all internals after timeout good idea? timeout means strange - so maybe reinitialize? // TODO: handle timeout events and properly maintain internal state private void waitForStateChangeOrFail(VlcMediaState state) { while ((VlcMediaState)getVlcState() != state) { if (logger.IsTraceEnabled) { logger.Trace(string.Format(CultureInfo.InvariantCulture, "Waiting for state. Current state is {0}, but expected {1}.", getVlcState(), state)); } if (stateChangeEventHandle.WaitOne(waitingRequiredStateTimeout, false)) { if ((VlcMediaState)getVlcState() == state) { return; } } else { if (logger.IsErrorEnabled) { logger.Error(string.Format(CultureInfo.InvariantCulture, "Failing with invalid state. Current state is {0}, but expected {1}.", getVlcState(), state)); } if ((VlcMediaState)getVlcState() != state) { throw new VlcTimeoutException("Timeout waiting required state."); } } } }
/// <summary> /// Waiting for change the state of <paramref name="mediaInternal"/> to the requested <paramref name="stateRequired"/>. /// <see cref="MediaPlayerException"/> exception will be thrown if operation will be timeouted. /// </summary> private void waitForMediaState(VlcMediaInternal mediaInternal, VlcMediaState stateRequired) { if (mediaInternal == null) { throw new ArgumentNullException("mediaInternal"); } // Stopwatch watch = timeoutWatch; try { TimeSpan timeout; lock (filtersWaitingThreadLock) { timeout = waitingRequiredStateTimeout; } // while (mediaInternal.State != stateRequired) { if (!watch.IsRunning) { watch.Start(); } if (watch.Elapsed > timeout) { throw new VlcTimeoutException("Timeout waiting required state."); } } } finally { watch.Stop(); watch.Reset(); } }