private bool _isBusy = false;
private void button1_Click(object sender, EventArgs e) => DownloadFile("someurl1", "somefilename1.exe");
private void button2_Click(object sender, EventArgs e) => DownloadFile("someurl2", "somefilename2.exe");
private void button3_Click(object sender, EventArgs e) => DownloadFile("someurl3", "somefilename3.exe");
private void button4_Click(object sender, EventArgs e) => DownloadFile("someurl4", "somefilename4.exe");
private void DownloadFile(string url, string fileName) {
if(_isBusy) return;
_isBusy = true;
var output = Path.Combine(Path.GetTempPath(), fileName); MessageBox.Show($"{fileName} will start downloading from {url}");
using (WebClient client = new WebClient()) {
client.DownloadFileCompleted += (sender, args) =>
{ MessageBox.Show($"{fileName} Complete!"); Process.Start(output); _isBusy = false; };
client.DownloadProgressChanged += (sender, args) => progressBar1.Value = args.ProgressPercentage; client.DownloadFileAsync(new Uri(url), output); } } }