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);
            }
        }
Beispiel #2
0
        private async Task CloseCleanupAsync()
        {
            Debug.WriteLine("SmMediaManager.CloseCleanupAsync()");
            List <Task>           tasks         = new List <Task>();
            ISegmentReaderManager readerManager = _readerManager;

            if (null != readerManager)
            {
                _readerManager = null;
                tasks.Add(readerManager.StopAsync());
            }
            IMediaStreamConfigurator msc = _mediaStreamConfigurator;

            if (null != msc)
            {
                tasks.Add(msc.CloseAsync());
            }
            if (_readers != null && _readers.Length > 0)
            {
                tasks.Add(CloseReadersAsync());
            }
            if (null != _playTask)
            {
                tasks.Add(_playTask);
            }
            if (tasks.Count > 0)
            {
                while (tasks.Any(t => !t.IsCompleted))
                {
                    try
                    {
                        Task t = TaskEx.Delay(2500);
                        Debug.WriteLine("SmMediaManager.CloseCleanupAsync() waiting for tasks");
                        Task task = await TaskEx.WhenAny(t, TaskEx.WhenAll(tasks)).ConfigureAwait(false);

                        Debug.WriteLine("SmMediaManager.CloseCleanupAsync() finished tasks");
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("SmMediaManager.CloseCleanupAsync() play task failed: " + ex.ExtendedMessage());
                    }
                }
            }
            if (null != msc)
            {
                msc.MediaManager = null;
            }
            DisposeReaders();
            readerManager?.DisposeSafe();
        }