コード例 #1
0
ファイル: SoundQueue.cs プロジェクト: Aldmi/SoundOutput
        /// <summary>
        /// Создания новой задачи разматывания очереди.
        /// </summary>
        public void StartQueue()
        {
            DispouseSoundMessageChangeRx = SoundMessageChangeRx.Subscribe(DefinitionStartStopQueueRxEventHandler);

            _cts         = new CancellationTokenSource();
            _currentTask = Task.Run(async() =>                //ЗАПУСК ЗАДАЧИ
            {
                //await CycleInvoke();
                await CycleInvokeUsingInternalSoundPlayerQueue();
            }, _cts.Token);

            IsWorking = true;

            _currentTask.ContinueWith(t =>                   //ОБРАБОТКА ОТМЕНЫ ЗАДАЧИ
            {
                IsWorking = false;
                DispouseSoundMessageChangeRx.Dispose();
            },
                                      TaskContinuationOptions.OnlyOnCanceled);

            _currentTask.ContinueWith(t =>                  //ОБРАБОТКА ЗАВЕРШЕННОЙ ЗАДАЧИ
            {
                IsWorking = false;
                DispouseSoundMessageChangeRx.Dispose();
            },
                                      TaskContinuationOptions.OnlyOnRanToCompletion);

            _currentTask.ContinueWith(t =>                  //ОБРАБОТКА Exception В ЗАДАЧИ
            {
                var ex = t.Exception;
                //...    обработка ошибки
                IsWorking = false;
                DispouseSoundMessageChangeRx.Dispose();
            },
                                      TaskContinuationOptions.OnlyOnFaulted);
        }
コード例 #2
0
ファイル: SoundQueue.cs プロジェクト: Aldmi/SoundOutput
 public void Dispose()
 {
     StopQueue();
     _player?.Dispose();
     DispouseSoundMessageChangeRx.Dispose();
 }