public ThunderTask(string url, string savefile) { URL = url; SaveFile = savefile; Param = ThunderDll.CreateDownTaskParam(url, savefile); Info = new ThunderDll.DownTaskInfo(); }
public Thunder() { InitSuccess = ThunderDll.Init(); timer.Interval = 1000; timer.Tick += Timer_Tick; timer.Start(); }
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(); } }
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); }
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); }
public void Dispose() { timer.Stop(); Exit = true; ThunderDll.Final(); }