Пример #1
0
        public void btnRemoveAll_Click(System.Object sender, System.EventArgs e)
        {
            DownloadFileAsyncExtended wClient = default(DownloadFileAsyncExtended);

            //// Always loop backwards when removing items from the list,
            //// because the index gets updated when an item is removed.
            //// This can result in certain items not getting removed.
            for (int i = ListViewEx.Items.Count - 1; i >= 0; i--)
            {
                if (ListViewEx.Items[i].Tag != null)
                {
                    //// Get the DownloadFileAsyncExtended class instance from the ListViewItem Tag.
                    wClient = (DownloadFileAsyncExtended)(ListViewEx.Items[i].Tag);
                    //// Pause (cancel) the download and remove it from the list.
                    wClient.CancelAsync();
                    ListViewEx.Items[i].Tag = null;
                    ListViewEx.Items[i].Remove();
                }
                else
                {
                    //// There's nothing to cancel, because the
                    //// download has finished or caused an error.
                    //// Just remove the item from the list.
                    ListViewEx.Items[i].Remove();
                }
            }
        }
Пример #2
0
        public void btnPauseAll_Click(System.Object sender, System.EventArgs e)
        {
            DownloadFileAsyncExtended wClient = default(DownloadFileAsyncExtended);

            for (int i = 0; i <= ListViewEx.Items.Count - 1; i++)
            {
                if (ListViewEx.Items[i].Tag != null)
                {
                    wClient = (DownloadFileAsyncExtended)(ListViewEx.Items[i].Tag);
                    //// Pause the download.
                    wClient.CancelAsync();
                }
            }
        }
Пример #3
0
        public void FormMain_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            DownloadFileAsyncExtended wClient = default(DownloadFileAsyncExtended);

            for (int i = 0; i <= ListViewEx.Items.Count - 1; i++)
            {
                //// Check if the Tag isn't Nothing, because else the download has already
                //// finished or an error occurred, so it can't be cancelled.
                if (ListViewEx.Items[i].Tag != null)
                {
                    //// Get the DownloadFileAsyncExtended class instance from the ListViewItem Tag.
                    wClient = (DownloadFileAsyncExtended)(ListViewEx.Items[i].Tag);
                    //// Cancel the download if it's still busy.
                    wClient.CancelAsync();
                }
            }
        }