Ejemplo n.º 1
0
        /// <summary>
        /// Construct a DownloadManager which can add pending downloads, and create threads to start downloading them
        /// </summary>
        /// <param name="threadHandler">The main ThreadHandler of the application</param>
        /// /// <param name="applicationInterface">The frontend interface of the application</param>
        public DownloadManager(ThreadHandler threadHandler, iGui applicationInterface)
        {
            this.threadHandler    = threadHandler;
            this.downloader       = new Downloader(threadHandler, applicationInterface, this);
            this.pendingDownloads = new List <Download>();
            this.activeDownloads  = new List <Download>();

            for (int i = 0; i < 4; i++)
            {
                Thread listener = new Thread(WaitForDownload);
                listener.Name = String.Format("{0} listener created by constructor", i);
                threadHandler.AddActive(listener);
                listener.Start();
            }

            //check if downloads folder is there and try to create it if not
            try
            {
                VerifyDownloadDirectory();
            }
            catch
            {
                applicationInterface.DisplayMessage("Unable to create downloads directory!");
            }
        }
Ejemplo n.º 2
0
        public void CancelDownload(Download video)
        {
            if (!video.Completed && activeDownloads.Contains(video))
            {
                int threadID = video.DownloadThread != null ? video.DownloadThread.ManagedThreadId : -1;
                while (video.DownloadThread != null && video.DownloadThread.IsAlive)
                {
                    Debug.WriteLine("Attempting download termination");

                    if (video.DownloadThread != null)
                    {
                        video.DownloadThread.Abort();
                    }
                }


                threadHandler.RemoveActive(threadID);
                activeDownloads.Remove(video);
                Debug.WriteLine("Download terminated");

                Thread listener = new Thread(WaitForDownload);
                listener.Name = String.Format("Re-listener: {0}", video.VideoData.Title);
                threadHandler.AddActive(listener);
                listener.Start();
            }
        }