hello all,
i have created a program ui and working fine however i have made a downloader class that is a dll with a form in it with other functions
got download working perfectly fine call it though a aync methord and put a call in for it but i have a issue with form 2 when i finished the download i use this.close()
and it closes both form 1 and form 2 for some reason i dont want to hide it i want to open it close it only code i have
calling function
public async Task webtest()
{
//kaori_webdownloader elfenform = new kaori_webdownloader();
//elfenform.Show();
////await elfenform.downloadupdate();
//// await elfenform.httpdownload();
//await elfenform.downloaderpython("");
if (IsVC2015Installed() == false)
{
kaori_webdownloader elfenvs = new kaori_webdownloader();
elfenvs.Show();
await elfenvs.downloadervs2019("");
}
else
{
XtraMessageBox.Show("VS 2019 Already installed.");
}
}
and this is the download functions.
public async Task downloadervs2019(string path)
{
if (os == "x86")
{
path = @"C:\Temp\" + "vc_redist.x64.exe";
filepath = path;
filename = "vc_redist.x64.exe";
httpdownloader = new HttpDownloader("https://aka.ms/vs/17/release/vc_redist.x64.exe", @"C:\Temp\" + Path.GetFileName("https://aka.ms/vs/17/release/vc_redist.x64.exe"));
httpdownloader.DownloadCompleted += Httpdownloader_DownloadCompleted;
httpdownloader.ProgressChanged += Httpdownloader_ProgressChanged;
Task.Run(() => httpdownloader.Start());
}
else
{
path = @"C:\Temp\" + "vc_redist.x86.exe";
filepath = path;
filename = "vc_redist.x86.exe";
httpdownloader = new HttpDownloader("https://aka.ms/vs/17/release/vc_redist.x86.exe", @"C:\Temp\" + Path.GetFileName("https://aka.ms/vs/17/release/vc_redist.x86.exe"));
httpdownloader.DownloadCompleted += Httpdownloader_DownloadCompleted;
httpdownloader.ProgressChanged += Httpdownloader_ProgressChanged;
Task.Run(() => httpdownloader.Start());
}
}
private void Httpdownloader_ProgressChanged(object sender, AltoHttp.ProgressChangedEventArgs e)
{
UpdateProgressBar((int)e.Progress);
lbl_percent.Text = $"{e.Progress.ToString("0.00")} %";
lbl_speed.Text = string.Format("{0} MB/s", (e.SpeedInBytes / 1024d / 1024d).ToString("0.00"));
lbl_downloaded.Text = string.Format("{0} MB/s", (httpdownloader.TotalBytesReceived / 1024d / 1024d).ToString("0.00"));
lbl_status.Text = "Downloading: " + filename;
}
private void Httpdownloader_DownloadCompleted(object sender, EventArgs e)
{
try
{
this.Invoke((MethodInvoker)delegate
{
lbl_status.Text = "Finished !";
lbl_percent.Text = "100%";
});
//Process.Start(filepath);
workerThread = new Thread(new ThreadStart(this.WorkerThread));
workerThread.Start();
using (Process p = new Process())
{
XtraMessageBox.Show(filepath);
p.StartInfo.FileName = filepath;
p.Start();
}
}
catch(Exception ex)
{
XtraMessageBox.Show(ex.Message);
}
}
public void closeme()
{
kaori_webdownloader elfen = new kaori_webdownloader();
elfen.Close();
}
and on the main form i have a refrence to to kaori dll,
and simple button click you
kaorires elfenres = new kaorires()
elfenres.Webtest();