示例#1
0
        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);
        }
示例#2
0
        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());
        }
示例#3
0
 public abstract void RunOnPass(ref NetTask content);
示例#4
0
 public static string DownloadString(NetTask task)
 {
     return(DownloadStringAsync(task).Result);
 }
示例#5
0
 public static string DownloadString(string url)
 {
     return(DownloadStringAsync(NetTask.MakeDefault(url)).Result);
 }
示例#6
0
 public static byte[] DownloadData(NetTask task)
 {
     return(DownloadDataAsync(task).Result);
 }
示例#7
0
 public static byte[] DownloadData(string url)
 {
     return(DownloadDataAsync(NetTask.MakeDefault(url)).Result);
 }
示例#8
0
 public static void DownloadFile(NetTask task)
 {
     DownloadFileAsync(task).Wait();
 }