コード例 #1
0
        void StopDownload()
        {
            speedMonitor?.DetachAll();
            speedMonitor = null;
            dlSaver?.DetachAll();
            dlSaver = null;
            download?.Stop();
            download       = null;
            requestBuilder = null;
            httpDlBuilder  = null;
            rdlBuilder     = null;
            dlChecker      = null;
            httpDlBuilder  = null;

            GC.Collect();
        }
コード例 #2
0
 public void StartDownload(string DownloadUrl, string SavePath = null)
 {
     RemainingTime = DownloadSpeed = 0;
     AvrDownload   = new List <int>()
     {
         0
     };
     AvrTime = new List <long>(0)
     {
         0
     };
     dlUri                       = new Uri(DownloadUrl);
     TempDirectoryName           = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TempDirectoryName);
     FinishedDirectoryName       = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FinishedDirectoryName);
     requestBuilder              = new SimpleWebRequestBuilder();
     dlChecker                   = new DownloadChecker();
     httpDlBuilder               = new SimpleDownloadBuilder(requestBuilder, dlChecker);
     rdlBuilder                  = new SDResumine(timeForHeartbeat, timeToRetry, maxRetries, httpDlBuilder);
     download                    = new MultiPartDownload(dlUri, bufferSize, numberOfParts, rdlBuilder, requestBuilder, dlChecker, null);
     download.DownloadCompleted += DownloadCompleted;
     download.DataReceived      += DataReceived;
     download.DownloadStopped   += DataStopped;
     download.DownloadCancelled += DataCancelled;
     download.DownloadStarted   += DataStarted;
     download.DownloadError     += DataError;
     progressMonitor             = new DownloadProgressMonitor();
     speedMonitor                = new DownloadSpeedMonitor(128);
     speedMonitor.Attach(download);
     if (SavePath == null)
     {
         SavePath = Path.Combine(TempDirectoryName, Path.GetFileName(dlUri.ToString()));
     }
     dlSaver = new DownloadToFileSaver(SavePath, Path.Combine(FinishedDirectoryName, Path.GetFileName(dlUri.ToString())));
     dlSaver.Attach(download);
     progressMonitor.Attach(download);
     download.Start();
 }