public static void stop(ThreadsAndDownloader threadAndDownloader)
 {
     threadAndDownloader.DownloaderThread.Abort();
     threadAndDownloader.Downloader.downloadstate = DownloadStates.stopped;
 }
        private static ThreadsAndDownloader startDownload(ControlledDownloader downloader)
        {
            Thread DMThread = new Thread(new ThreadStart(downloader.download));
            DMThread.IsBackground = true;

            ThreadsAndDownloader threadAndDownloader = new ThreadsAndDownloader(
                downloader, DMThread);

            ThreadsToDownloaderTable.Add(threadAndDownloader);

            DMThread.Start();

            return threadAndDownloader;
        }
 public static void pause(ThreadsAndDownloader threadAndDownloader)
 {
     threadAndDownloader.DownloaderThread.Suspend();
     //updateProgress(threadAndDownloader);
     threadAndDownloader.Downloader.downloadstate = DownloadStates.paused;
 }
 public static void resume(ThreadsAndDownloader threadAndDownloader)
 {
     threadAndDownloader.DownloaderThread.Resume();
     //updateProgress(threadAndDownloader);
     threadAndDownloader.Downloader.downloadstate = DownloadStates.running;
 }
 public static void open(ThreadsAndDownloader threadAndDownloader)
 {
     threadAndDownloader.Downloader.open();
 }
        public void ProcessParameters(object sender, string[] args)
        {
            // The form has loaded, and initialization will have been be done.
            // Add the command-line arguments to our textbox, just to confirm that
            // it reached here.
            if (args != null && args.Length != 0)
            {

                try
                {
                    threadAndDownloader = ThreadManager.download(args[0]);
                    setStatusMessage("Download Started : " + args[0]);
                    //updateListBox();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
                }

            }
        }
        private void stop()
        {
            int stoppedCount = 0;
            foreach (ProgressBarPanel pgPanel in progressPanelsList)
            {
                if (pgPanel.selectThreadChkBox.Checked == true)
                {
                    stoppedCount++;

                    threadAndDownloader = DownloadersAndPanels.getDownloaderThread(pgPanel.progressPanel);

                    ThreadManager.stop(threadAndDownloader);
                    MessageBox.Show("Stopped : " + threadAndDownloader.Downloader.Url + " " + threadAndDownloader.Downloader.BytesDownloaded);
                    //MessageBox.Show("Paused : " + threadAndDownloader.Downloader.Url + " " + threadAndDownloader.Downloader.BytesDownloaded);
                    // MessageBox.Show("Hello");
                }
            }
            //ThreadManager.pause(threadAndDownloader);
            setStatusMessage("Download(s) Stopped : " + stoppedCount);
            //MessageBox.Show("OOps");
        }
        private void StartDwnldBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (SavetxtBox.Text != "")
                {
                    threadAndDownloader = ThreadManager.download(URLTextBox.Text, SavetxtBox.Text);
                }
                else
                {
                    threadAndDownloader = ThreadManager.download(URLTextBox.Text);
                }

                //Associate Panel with Downloader
                DownloaderThreadAndProgressPanel downloaderAndPanel = new DownloaderThreadAndProgressPanel();
                ProgressBarPanel pgPanel = new ProgressBarPanel(panelsCount);
                panelsCount++;
                pgPanel.infoLabel.Text += URLTextBox.Text;

                progressPanelsList.Add(pgPanel);
                downloaderAndPanel.threadAndDownloader = this.threadAndDownloader;
                downloaderAndPanel.pgPanel = pgPanel;

                //comment out later
             //       pgPanel.progressBar.Value = 70;
                //Never forget or u shalt be damned!

                DownloadersAndPanels.downloadersAndPanels.Add(downloaderAndPanel);

                //add panel to mainform
                DownloadQueuePanel.Controls.Add(pgPanel.progressPanel);

                // Display Status bar message
                setStatusMessage("Download Started : " + URLTextBox.Text);

                this.intializeTimer();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
            }
        }
        private void resume()
        {
            //statusLbl.Text = "Download Resumed";
            //ThreadManager.resume(threadAndDownloader);
            //setStatusMessage("Download Resumed : " + URLTextBox.Text);

            int resumedCount = 0;
            foreach (ProgressBarPanel pgPanel in progressPanelsList)
            {
                if (pgPanel.selectThreadChkBox.Checked == true)
                {
                    resumedCount++;

                    threadAndDownloader = DownloadersAndPanels.getDownloaderThread(pgPanel.progressPanel);

                    ThreadManager.resume(threadAndDownloader);
                    MessageBox.Show("Resumed : " + threadAndDownloader.Downloader.Url + " " + threadAndDownloader.Downloader.BytesDownloaded);
                    //MessageBox.Show("Paused : " + threadAndDownloader.Downloader.Url + " " + threadAndDownloader.Downloader.BytesDownloaded);
                    // MessageBox.Show("Hello");
                }
            }
            //ThreadManager.pause(threadAndDownloader);
            setStatusMessage("Download(s) Resumed : " + resumedCount);
            //MessageBox.Show("OOps");
        }