Пример #1
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;
                Program.Scheduler.Add(task);
                iter++;
            }

            interrupt.WaitOne();

            return(result.ToList());
        }
Пример #2
0
 public static string DownloadString(NetTask task)
 {
     return(DownloadStringAsync(task).Result);
 }
Пример #3
0
 public static string DownloadString(string url)
 {
     return(DownloadStringAsync(NetTask.MakeDefault(url)).Result);
 }
Пример #4
0
 public abstract void RunOnPass(ref NetTask content);