示例#1
0
        /// <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(() => { }));
            }
        }
示例#2
0
        /// <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();
        }