Esempio n. 1
0
 public ThunderTask(string url, string savefile)
 {
     URL      = url;
     SaveFile = savefile;
     Param    = ThunderDll.CreateDownTaskParam(url, savefile);
     Info     = new ThunderDll.DownTaskInfo();
 }
Esempio n. 2
0
        public Thunder()
        {
            InitSuccess = ThunderDll.Init();

            timer.Interval = 1000;
            timer.Tick    += Timer_Tick;
            timer.Start();
        }
Esempio n. 3
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();

            foreach (var task in Tasks.Values)
            {
                if (!task.IsStart || task.IsStop || task.IsComplete)
                {
                    continue;
                }

                ThunderDll.QueryTaskInfo(task.ID, task.Info);

                if (task.Info.Status == ThunderDll.DOWN_TASK_STATUS.TSC_STOPENDING)
                {
                    task.IsStop = true;
                }

                if (task.Info.Status == ThunderDll.DOWN_TASK_STATUS.TSC_COMPLETE)
                {
                    TaskComplete?.Invoke(this, task);
                    task.IsComplete = true;
                }

                TaskInfoChange?.Invoke(this, task);
            }

            if (AutoManage)
            {
                int cnt = RunTaskCount();
                if (cnt < MaxTaskCount)
                {
                    foreach (var task in Tasks.Values)
                    {
                        if (!task.IsStart)
                        {
                            task.StartTask();
                            cnt++;
                        }

                        if (cnt >= MaxTaskCount)
                        {
                            break;
                        }
                    }
                }

                DeleteCompleted();
            }

            if (!Exit)
            {
                timer.Start();
            }
        }
Esempio n. 4
0
        public bool DeleteTask(ThunderTask task, bool deletefile = false)
        {
            bool result = ThunderDll.DeleteTask(task.ID);

            if (deletefile)
            {
                ThunderDll.DelTempFile(task.Param);
            }

            Tasks.TryRemove(task.URL, out _);
            return(result);
        }
Esempio n. 5
0
        public ThunderTask CreateTask(string url, string savefile)
        {
            if (Tasks.ContainsKey(url))
            {
                return(Tasks[url]);
            }

            ThunderTask task = new ThunderTask(url, savefile);

            task.ID = ThunderDll.CreateTask(task.Param);
            Tasks.TryAdd(url, task);
            return(task);
        }
Esempio n. 6
0
 public void Dispose()
 {
     timer.Stop();
     Exit = true;
     ThunderDll.Final();
 }