/// <summary> /// Calls the execution of the given command instance /// and wait for its completion without blocking the dispatcher /// </summary> /// <param name="command">The command.</param> private void ExecuteAndWaitFor(MediaCommand command) { var executeTask = Task.Run(() => { if (command.HasCompleted) { return; } command.Execute(); }); var waitTask = Task.Run(async() => { while (command.HasCompleted == false) { await Task.Delay(10); } }); while (waitTask.IsCompleted == false) { // Pump invoke Dispatcher.CurrentDispatcher.Invoke( DispatcherPriority.Background, new Action(() => { })); } }
/// <summary> /// Enqueues the command for execution. /// </summary> /// <param name="command">The command.</param> private void EnqueueCommand(MediaCommand command) { if (MediaElement.IsOpen == false) { command.Complete(); return; } lock (SyncLock) Commands.Add(command); }
/// <summary> /// Processes the next command in the command queue. /// This method is called in every block rendering cycle. /// </summary> public void ProcessNext() { MediaCommand command = null; lock (SyncLock) { if (Commands.Count == 0) { return; } command = Commands[0]; Commands.RemoveAt(0); } command.Execute(); }
/// <summary> /// Waits for the command to complete execution. /// </summary> /// <param name="command">The command.</param> private void WaitFor(MediaCommand command) { var waitTask = Task.Run(async() => { while (command.HasCompleted == false && MediaElement.IsOpen) { await Task.Delay(10); } }); while (waitTask.IsCompleted == false) { // Pump invoke Dispatcher.CurrentDispatcher.Invoke( DispatcherPriority.Background, new Action(() => { })); } }