- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
private List<string> urls = new List<string>();
private int urls_index = -1;
private ProgressBar pb = new ProgressBar()
{
Width = 291,
Height = 26,
Maximum = 100,
Minimum = 0,
Location = new Point(12, 41)
};
public Object SyncIndex = new Object();
public void DownLoad(object index)
{
int indexwhile = (int) index;
while (work)
{
int localIndex;
lock (SyncIndex)
{
urls_index++;
localIndex = urls_index;
}
WebClient webClient = new WebClient();
try
{
webClient.DownloadFile(new Uri(urls[localIndex]), "img/" + localIndex + ".jpg");
webClient.DownloadProgressChanged += (s, a) => Invoke(new Action(() => {progressBars[indexwhile].Value = a.ProgressPercentage;}));
}
catch (Exception exception)
{
Invoke(new Action(() =>
{
listBox2.Items.Add("Ошибка" + listBox1.Items[localIndex]);
}));
DownLoad(index);
}
Invoke(new Action(() =>
{
listBox1.Items[localIndex] = "Загружен" + listBox1.Items[localIndex];
label1.Text = urls.Count.ToString();
richTextBox1.Text += localIndex + @".jpg Загружен" + Environment.NewLine;
}));
Thread.Sleep(500);
}
}
private void button2_Click(object sender, EventArgs e)
{
work = true;
Thread[] threads = new Thread[30];
for (int i = 0; i < 20; i++)
{
int mnoj = i + 1;
progressBars[i] = new ProgressBar()
{
Width = 291,
Height = 26,
Maximum = 100,
Minimum = 0,
Location = new Point(12, 41)
};
progressBars[i].Location = new Point(12, 41 * mnoj);
Controls.Add(progressBars[i]);
threads[i] = new Thread(DownLoad);
threads[i].IsBackground = true;
threads[i].Start(i);
}
}