Exemple #1
0
        /// <summary>
        /// Starts displaying all views in order of their insertion into the queue
        /// </summary>
        public async void Show()
        {
            if (mQueue.Count != 0)
            {
                mCurrent = mQueue.Dequeue();
                mCurrentOriginalDismissListener = mCurrent.DismissListener;
                mCurrent.DismissListener        = this;
                mCurrent.Show();

                if (autoRunDelay != null)
                {
                    await Task.Delay((TimeSpan)autoRunDelay);

                    if (mQueue.Count > 0)
                    {
                        mCurrent.Hide();
                    }
                    else if (mQueue.Count == 0 && autoRunClosesQueue)
                    {
                        mCurrent.Hide();
                    }
                }
            }
            else if (QueueCompleted != null)
            {
                QueueCompleted.Invoke(this, new EventArgs()
                {
                });
            }
        }
Exemple #2
0
        private async void ProcessQueue()
        {
            var activeJobs     = new List <Task>();
            var resultReported = false;
            var failed         = 0;
            var succeeded      = 0;

            do
            {
                while (activeJobs.Count < ConcurrentWorkers && this.queue.TryDequeue(out var worker))
                {
                    activeJobs.Add(worker.SyncAsync());
                }

                if (activeJobs.Count > 0)
                {
                    resultReported = false;
                    await Task.WhenAny(activeJobs);

                    failed    += activeJobs.Count(x => x.IsFaulted && x.IsCompleted);
                    succeeded += activeJobs.Count(x => !x.IsFaulted && x.IsCompleted);
                    activeJobs = activeJobs.Where(x => !x.IsCompleted).ToList();
                }
                else
                {
                    if (!resultReported && QueueCompleted != null)
                    {
                        QueueCompleted?.Invoke(this, new QueueCompletedEventArgs(Volatile.Read(ref queueSize), succeeded, failed));
                        resultReported = true;
                    }

                    succeeded = 0;
                    failed    = 0;
                    Volatile.Write(ref queueSize, 0);
                    System.Threading.Thread.Sleep(100);
                }
            } while (this.enabled);
        }
Exemple #3
0
        private void Downloader_DownloadError(object sender, System.EventArgs e)
        {
            QueueElementCompleted?.Invoke(this, new QueueElementCompletedEventArgs(CurrentIndex, _currentElement));
            for (var i = 0; i < _elements.Count; i++)
            {
                if (_elements[i].Equals(_currentElement))
                {
                    _elements[i] = new HttpDownloadQueueElement
                    {
                        Id          = _elements[i].Id,
                        Url         = _elements[i].Url,
                        Destination = _elements[i].Destination,
                        Completed   = true
                    };
                    break;
                }
            }

            var active = Form.ActiveForm;

            if (active != null && active.InvokeRequired)
            {
                active.BeginInvoke((MethodInvoker) delegate
                {
                    MessageBox.Show("Download error occurred. Please check your connection, and that the content requested is available for download.",
                                    "Download Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                });
            }
            else
            {
                MessageBox.Show("Download error occurred. Please check your connection, and that the content requested is available for download.",
                                "Download Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            QueueCompleted?.Invoke(this, new System.EventArgs());
        }