public static async Task DownloadFileAsync(NetTask task) { await Task.Run(() => { var interrupt = new ManualResetEvent(false); task.SaveFile = true; task.CompleteCallback = () => { interrupt.Set(); }; task.ErrorCallback = (code) => { task.ErrorCallback = null; interrupt.Set(); }; AppProvider.Scheduler.Add(task); interrupt.WaitOne(); }).ConfigureAwait(false); }
public static List <string> DownloadStrings(List <string> urls, string cookie = "", Action complete = null) { var interrupt = new ManualResetEvent(false); var result = new string[urls.Count]; var count = urls.Count; int iter = 0; foreach (var url in urls) { var itertmp = iter; var task = NetTask.MakeDefault(url); task.DownloadString = true; task.CompleteCallbackString = (str) => { result[itertmp] = str; if (Interlocked.Decrement(ref count) == 0) { interrupt.Set(); } complete?.Invoke(); }; task.ErrorCallback = (code) => { if (Interlocked.Decrement(ref count) == 0) { interrupt.Set(); } }; task.Cookie = cookie; AppProvider.Scheduler.Add(task); iter++; } interrupt.WaitOne(); return(result.ToList()); }
public static string DownloadString(NetTask task) { return(DownloadStringAsync(task).Result); }
public static string DownloadString(string url) { return(DownloadStringAsync(NetTask.MakeDefault(url)).Result); }
public static byte[] DownloadData(NetTask task) { return(DownloadDataAsync(task).Result); }
public static byte[] DownloadData(string url) { return(DownloadDataAsync(NetTask.MakeDefault(url)).Result); }
public static void DownloadFile(NetTask task) { DownloadFileAsync(task).Wait(); }