Exemplo n.º 1
0
        private bool doDownload(DownloadFile file, int failedCount)
        {
            try
            {
                if (failedCount > 2)
                {
                    return(false);
                }

                var downloader = new WebDownload();
                //Console.WriteLine("start " + file.Name);
                downloader.DownloadFileLimit(file.Url, file.Path);
                //Console.WriteLine("end " + file.Name);

                Interlocked.Increment(ref progressed);

                var ev = Task.Run(() =>
                {
                    fireDownloadFileChangedEvent(file.Type, file.Name, total, progressed);
                });
                return(true);
            }
            catch (Exception ex)
            {
                //System.Diagnostics.Debug.WriteLine(ex);
                failedCount++;

                return(doDownload(file, failedCount));
            }
        }
Exemplo n.º 2
0
        private void doDownload(DownloadFile file)
        {
            try
            {
                WebDownload downloader = new WebDownload();
                downloader.DownloadFileLimit(file.Url, file.Path);

                if (file.AfterDownload != null)
                {
                    foreach (var item in file.AfterDownload)
                    {
                        item?.Invoke();
                    }
                }

                Interlocked.Increment(ref progressed);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            finally
            {
                Task.Run(() =>
                {
                    fireDownloadFileChangedEvent(file.Type, file.Name, total, progressed);
                });
            }
        }