Example #1
0
        /// <summary>
        /// Synchronously adds the <paramref name="cameraTask"/> given to an execution queue
        /// and returns awaitable task to wait for the <paramref name="cameraTask"/> completion.
        /// </summary>
        /// <param name="cameraTask">Task to enqueue.</param>
        /// <returns>Awaitable task.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="cameraTask"/> is <see langword="null"/>.</exception>
        public Task EnqueueTaskAsync(ICameraTask cameraTask)
        {
            if (cameraTask == null)
            {
                throw new ArgumentNullException("cameraTask");
            }

            QueuedCameraTask task = this.AddTaskToQueue(cameraTask);

            return(Task.Run(() => task.WaitForComplete(Timeout.InfiniteTimeSpan)));
        }
Example #2
0
        /// <summary>
        /// Adds the <paramref name="cameraTask"/> specified to the execution queue.
        /// </summary>
        /// <param name="cameraTask">The camera task to add to the queue.</param>
        /// <returns>Execution wrapper for the <paramref name="cameraTask"/> given.</returns>
        private QueuedCameraTask AddTaskToQueue(ICameraTask cameraTask)
        {
            QueuedCameraTask queuedTask = new QueuedCameraTask(cameraTask);

            lock (this.syncRoot)
            {
                this.pendingTasks.Add(queuedTask);

                this.ScheduleNextTask();
            }

            return(queuedTask);
        }
Example #3
0
        /// <summary>
        /// Schedules the next pending task for execution, if needed.
        /// </summary>
        private void ScheduleNextTask()
        {
            lock (this.syncRoot)
            {
                if (this.currentTask != null || !this.pendingTasks.Any())
                {
                    return;
                }

                this.currentTask = this.pendingTasks[0];
                this.currentTask.Task.Complete += this.CameraTaskCompleted;

                this.pendingTasks.RemoveAt(0);

                ThreadPool.QueueUserWorkItem(state => this.StartCurrentTask());
            }
        }
Example #4
0
        /// <summary>
        /// The <see cref="ICameraTask.Complete"/> event handler.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void CameraTaskCompleted(object sender, EventArgs e)
        {
            lock (this.syncRoot)
            {
                // Makes sure that the current method isn't called for the second
                // time for the same task.
                if (this.currentTask == null || this.currentTask.Task != sender)
                {
                    return;
                }

                this.currentTask.Task.Complete -= this.CameraTaskCompleted;
                this.currentTask.Dispose();
                this.currentTask = null;

                this.ScheduleNextTask();
            }
        }
        /// <summary>
        /// The <see cref="ICameraTask.Complete"/> event handler.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void CameraTaskCompleted(object sender, EventArgs e)
        {
            lock (this.syncRoot)
            {
                // Makes sure that the current method isn't called for the second
                // time for the same task.
                if (this.currentTask == null || this.currentTask.Task != sender)
                {
                    return;
                }

                this.currentTask.Task.Complete -= this.CameraTaskCompleted;
                this.currentTask.Dispose();
                this.currentTask = null;

                this.ScheduleNextTask();
            }
        }
        /// <summary>
        /// Schedules the next pending task for execution, if needed.
        /// </summary>
        private void ScheduleNextTask()
        {
            lock (this.syncRoot)
            {
                if (this.currentTask != null || !this.pendingTasks.Any())
                {
                    return;
                }

                this.currentTask = this.pendingTasks[0];
                this.currentTask.Task.Complete += this.CameraTaskCompleted;

                this.pendingTasks.RemoveAt(0);

                ThreadPool.QueueUserWorkItem(state => this.StartCurrentTask());
            }
        }
        /// <summary>
        /// Adds the <paramref name="cameraTask"/> specified to the execution queue.
        /// </summary>
        /// <param name="cameraTask">The camera task to add to the queue.</param>
        /// <returns>Execution wrapper for the <paramref name="cameraTask"/> given.</returns>
        private QueuedCameraTask AddTaskToQueue(ICameraTask cameraTask)
        {
            QueuedCameraTask queuedTask = new QueuedCameraTask(cameraTask);

            lock (this.syncRoot)
            {
                this.pendingTasks.Add(queuedTask);

                this.ScheduleNextTask();
            }

            return queuedTask;
        }