Exemplo n.º 1
0
        private static void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            form.BeginInvoke((MethodInvoker) delegate
            {
                DownloadPath dl = _downloads.Count > 0 ? _downloads.Dequeue() : null;
                if (dl != null && !cancellingDownload)
                {
                    NextDownload(dl);
                }
                else
                {
                    //Check if files are complete??
                    if (packType == PackType.Client)
                    {
                        frmMain.runClient = true;
                    }
                    else
                    {
                        frmMain.runServer = true;
                    }
                    frmMain.downloadingData = false;
                }

                DownloadCompleted(dl == null);
            });
        }
Exemplo n.º 2
0
        private static void NextDownload(DownloadPath dl)
        {
            Thread thread = new Thread(() =>
            {
                curDownload = dl;
                string fol  = Path.GetDirectoryName(dl.Path);
                if (!Directory.Exists(fol))
                {
                    Directory.CreateDirectory(fol);
                }

                using (client = new WebClient())
                {
                    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                    client.DownloadFileCompleted   += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
                    client.DownloadFileAsync(dl.Url, dl.Path);
                }
            });

            if (!cancellingDownload)
            {
                thread.Start();
            }
        }