private async Task CleanupFailedOpenAsync(Task <IMediaReader>[] readerTasks) { Debug.WriteLine("SmMediaManager.CleanupFailedOpenAsync() state " + (object)this.State); this._playbackCancellationTokenSource.Cancel(); if (this._readers == null && null != readerTasks) { this._readers = Enumerable.ToArray <IMediaReader>(Enumerable.Select <Task <IMediaReader>, IMediaReader>(Enumerable.Where <Task <IMediaReader> >((IEnumerable <Task <IMediaReader> >)readerTasks, (Func <Task <IMediaReader>, bool>)(r => { if (null == r) { return(false); } AggregateException exception = r.Exception; if (null == exception) { return(r.IsCompleted); } Debug.WriteLine("SmMediaManager.CleanupFailedOpenAsync(): reader create failed: " + exception.Message); return(false); })), (Func <Task <IMediaReader>, IMediaReader>)(r => r.Result))); await this.CloseReadersAsync().ConfigureAwait(false); this.DisposeReaders(); } if (null != this._readerManager) { DisposeExtensions.DisposeSafe((IDisposable)this._readerManager); this._readerManager = (ISegmentReaderManager)null; } }
private void CleanupMediaStreamSource() { TsMediaStreamSource mediaStreamSource = this._mediaStreamSource; if (null == mediaStreamSource) { return; } this._mediaStreamSource = (TsMediaStreamSource)null; DisposeExtensions.DisposeSafe((IDisposable)mediaStreamSource); }
private void CleanupMediaManager(IMediaManager mediaManager) { Debug.WriteLine("MediaStreamFacadeBase.CleanupMediaManager()"); if (null == mediaManager) { return; } mediaManager.OnStateChange -= new EventHandler <MediaManagerStateEventArgs>(this.MediaManagerOnStateChange); DisposeExtensions.DisposeSafe((IDisposable)mediaManager); this._mediaManagerBuilder.Destroy(mediaManager); Debug.WriteLine("MediaStreamFacadeBase.CleanupMediaManager() completed"); }
private async Task CloseCleanupAsync() { Debug.WriteLine("SmMediaManager.CloseCleanupAsync()"); List <Task> tasks = new List <Task>(); ISegmentReaderManager readerManager = this._readerManager; if (null != readerManager) { this._readerManager = (ISegmentReaderManager)null; tasks.Add(readerManager.StopAsync()); } IMediaStreamConfigurator msc = this._mediaStreamConfigurator; if (null != msc) { tasks.Add(msc.CloseAsync()); } if (this._readers != null && this._readers.Length > 0) { tasks.Add(this.CloseReadersAsync()); } if (null != this._playTask) { tasks.Add(this._playTask); } if (tasks.Count > 0) { while (Enumerable.Any <Task>((IEnumerable <Task>)tasks, (Func <Task, bool>)(t => !t.IsCompleted))) { try { Task t = TaskEx.Delay(2500); Debug.WriteLine("SmMediaManager.CloseCleanupAsync() waiting for tasks"); Task task = await TaskEx.WhenAny(t, TaskEx.WhenAll((IEnumerable <Task>)tasks)).ConfigureAwait(false); Debug.WriteLine("SmMediaManager.CloseCleanupAsync() finished tasks"); } catch (Exception ex) { Debug.WriteLine("SmMediaManager.CloseCleanupAsync() play task failed: " + ExceptionExtensions.ExtendedMessage(ex)); } } } if (null != msc) { msc.MediaManager = (IMediaManager)null; } this.DisposeReaders(); if (null != readerManager) { DisposeExtensions.DisposeSafe((IDisposable)readerManager); } }
public void Destroy(TBuild instance) { IBuilderHandle <TBuild> builderHandle = Interlocked.Exchange <IBuilderHandle <TBuild> >(ref this._handle, (IBuilderHandle <TBuild>)null); if (null == builderHandle) { throw new InvalidOperationException("No handle"); } if (!object.ReferenceEquals((object)instance, (object)builderHandle.Instance)) { throw new InvalidOperationException("Wrong instance"); } DisposeExtensions.DisposeSafe((IDisposable)builderHandle); }
public TBuild Create() { if (null != this._handle) { throw new InvalidOperationException("The builder is in use"); } BuilderHandle <TBuild> builderHandle = new BuilderHandle <TBuild>(this.Container.BeginLifetimeScope((object)"builder-scope")); if (null != Interlocked.CompareExchange <IBuilderHandle <TBuild> >(ref this._handle, (IBuilderHandle <TBuild>)builderHandle, (IBuilderHandle <TBuild>)null)) { DisposeExtensions.DisposeSafe((IDisposable)builderHandle); throw new InvalidOperationException("The builder is in use"); } return(builderHandle.Instance); }
protected virtual void Dispose(bool disposing) { Debug.WriteLine("MediaStreamFacadeBase.Dispose({0})", (object)(bool)(disposing ? 1 : 0)); if (!disposing) { return; } if (!this._closeCancellationTokenSource.IsCancellationRequested) { this._closeCancellationTokenSource.Cancel(); } if (!this._disposeCancellationTokenSource.IsCancellationRequested) { this._disposeCancellationTokenSource.Cancel(); } this._asyncLock.LockAsync(CancellationToken.None).Wait(); this.StateChange = (EventHandler <MediaManagerStateEventArgs>)null; bool lockTaken = false; object obj; IMediaManager mediaManager; try { Monitor.Enter(obj = this._lock, ref lockTaken); mediaManager = this._mediaManager; this._mediaManager = (IMediaManager)null; } finally { if (lockTaken) { Monitor.Exit(obj); } } if (null != mediaManager) { this.CleanupMediaManager(mediaManager); } DisposeExtensions.DisposeSafe((IDisposable)this._mediaManagerBuilder); this._asyncLock.Dispose(); this._closeCancellationTokenSource.Dispose(); this._disposeCancellationTokenSource.Dispose(); }