/// <summary>
        /// 全局状态
        /// </summary>
        private void GetGlobalStatus()
        {
            try
            {
                Aria2cGlobalStat status = this.GetGlobalStat();
                if (status == null)
                {
                    return;
                }

                if (globalStat.DownloadSpeed != status.DownloadSpeed ||
                    globalStat.UploadSpeed != status.UploadSpeed ||
                    globalStat.NumActive != status.NumActive ||
                    globalStat.NumWaiting != status.NumWaiting ||
                    globalStat.NumStopped != status.NumStopped ||
                    globalStat.NumStoppedTotal != status.NumStoppedTotal)
                {
                    OnGlobalStatusChanged?.Invoke(this, new Aria2cGlobalStatEvent(status));
                    globalStat = status;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#2
0
        /// <summary>
        /// 全局状态
        /// </summary>
        private async void GetGlobalStatus(Aria2cGlobalStat status)
        {
            try
            {
                if (status == null && isCycle)
                {
                    status = this.GetGlobalStat();
                }
                if (status == null)
                {
                    return;
                }

                if (globalStat.DownloadSpeed != status.DownloadSpeed || globalStat.UploadSpeed != status.UploadSpeed || globalStat.NumActive != status.NumActive ||
                    globalStat.NumWaiting != status.NumWaiting || globalStat.NumStopped != status.NumStopped || globalStat.NumStoppedTotal != status.NumStoppedTotal)
                {
                    OnGlobalStatusChanged?.Invoke(this, new Aria2cGlobalStatEvent(status));
                    globalStat = status;
                }

                if (status.NumActive == 0L && status.NumWaiting == 0L && status.DownloadSpeed == 0L && isCycle)
                {
                    await Task.Delay(Convert.ToInt32(this.dInterval * 3)); //等待3秒后,再做判断,避免刚添加完任务的瞬间,误判定为全部结束

                    status = this.GetGlobalStat();                         //获取最新status
                    //timerTMP == null是一个flag,表明OnAllFinish没有触发过
                    if (status.NumActive == 0L && status.NumWaiting == 0L && status.DownloadSpeed == 0L && !IsLoading && timerTMP == null)
                    {
                        OnAllFinish?.Invoke(this, new Aria2cGlobalStatEvent(status));

                        StartTmpTimer();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#3
0
        /// <summary>
        /// 全局状态
        /// </summary>
        private void GetGlobalStatus(Aria2cGlobalStat status)
        {
            try
            {
                if (status == null && !IsPauseAll)
                {
                    status = this.GetGlobalStat();
                }
                if (status == null)
                {
                    return;
                }

                if (globalStat.DownloadSpeed != status.DownloadSpeed || globalStat.UploadSpeed != status.UploadSpeed || globalStat.NumActive != status.NumActive ||
                    globalStat.NumWaiting != status.NumWaiting || globalStat.NumStopped != status.NumStopped || globalStat.NumStoppedTotal != status.NumStoppedTotal)
                {
                    OnGlobalStatusChanged?.Invoke(this, new Aria2cGlobalStatEvent(status));
                    globalStat = status;
                }

                if (status.NumActive == 0 && status.NumWaiting == 0 && status.DownloadSpeed == 0 && !IsPauseAll)
                {
                    OnAllFinish?.Invoke(this, new Aria2cGlobalStatEvent(status));

                    if (timerTMP == null)
                    {
                        timerTMP           = new Timer(10000);//10s后执行(等待其他如GlobalStatus),改变“暂停”变量,减少计时器轮询操作
                        timerTMP.Elapsed  += new ElapsedEventHandler(SetPauseAll);
                        timerTMP.AutoReset = false;
                        timerTMP.Start();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }