2019-07-31 13:15:29

Hello!
Did I implement it properly? Is there some better way to do this? here's my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HawkEyezxsj
{
    public partial class WND_Main : Form
    {
        WebClient Client = new WebClient();
        int counter = 0;
        public string[] ListOfFiles = File.ReadAllLines("list.txt");
        public WND_Main()
        {
            InitializeComponent();
        }
        private void BTN_GetUpdate_Click(object sender, EventArgs e)
        {
            Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Client_DownloadProgressChanged);
            Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Client_DownloadFileCompleted);
            foreach (var item in ListOfFiles)
            {
                Client.DownloadFileAsync(new System.Uri("https://nuno-software.pl/projects/HawkEye/" + item + ""),item);
            }
            Client.DownloadFileAsync(new System.Uri("https://nuno-software.pl/projects/HawkEye/HawkEye_Demo.exe"), "HawkEye_Demo.exe");
            BTN_GetUpdate.Text = "Downloading";
            BTN_GetUpdate.Enabled = false;
        }
        void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            PRG_Download.Value = e.ProgressPercentage;
                }
        void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            counter++;
            if (counter == ListOfFiles.Length)
            {
                MessageBox.Show("The update has been downloaded and applied. The program will be started now.");
                Process.Start("HawkEye_Demo.exe");
                this.Close();
            }
        }
        private void PRG_Download_Click(object sender, EventArgs e)
        {
        }
    }
}

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2019-07-31 16:35:54

I think you have, though your going to need a lot more progress bars or figure out an overall percentage. One progress bar won't be enough to monitor all downloads at once without some kind of overall percentage.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2019-07-31 22:33:53

Thank you Ethin for your help.
That was justan initial versionwhich wascreated to testthe implementation.

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com