void End_DownLoad(ClassDownLoad thread, bool isSuccess) { lock (ObjObject) { downloadCount--; } SetStatus("Completed", thread); SetProgressBar(); Downloading(); }
private void buttonDownload_Click(object sender, EventArgs e) { a_intent = new ArrayList(); a_thread = new ArrayList(); downloadCount = 0; if (listViewgetFiles.CheckedItems.Count == 0) { MessageBox.Show("No items Select"); } else { ClassDownLoad download = null; progressBarPrograss.Minimum = 0; progressBarPrograss.Maximum = listViewgetFiles.CheckedItems.Count; progressBarPrograss.Value = 0; foreach (ListViewItem Listitem in listViewgetFiles.CheckedItems) { Listitem.SubItems[1].Text = "Not started"; download = new ClassDownLoad(Listitem.SubItems[0].Text, textBoxFileLocation.Text); Listitem.Tag = download; try { ThreadStart tsDelegate = new ThreadStart(download.StartDownload); download.DownloadStarting += new ClassDownLoad._delDownloadStarting(Start_download); download.DownloadCompleted += new ClassDownLoad._delDownloadCompleted(End_DownLoad); Thread t = new Thread(tsDelegate); t.Name = Listitem.SubItems[0].Text; a_thread.Add(t); a_intent.Add(download); } catch { Listitem.SubItems[1].Text = "Error"; } } Downloading(); } }
private void Downloading() { try { int j = 0; int limit = int.Parse(textBoxDownloadCounter.Text); int iCount = 0; lock (ObjObject) { iCount = a_intent.Count; } if (iCount != 0) { foreach (Thread thread in a_thread) { ClassDownLoad file = ((ClassDownLoad)a_intent[j]); if (file._IsStarted == false) { lock (ObjObject) { thread.Start(); downloadCount++; } } if (downloadCount == limit) { break; } j++; } } else { } } catch { MessageBox.Show("Enter the number of Threads"); } }
//---------------------------------------------- private void SetStatus(string Status, ClassDownLoad f) { if (listViewgetFiles.InvokeRequired) { delSetStatus s = new delSetStatus(SetStatus); this.Invoke(s, new object[] { Status, f }); } else { foreach (ListViewItem item in listViewgetFiles.Items) { if (item.Tag == f) { lock (ObjObject) { item.SubItems[1].Text = Status; } break; } } } }
void Start_download(ClassDownLoad thread) { SetStatus("Downloading", thread); }