Reputation: 23
My problem is that the statusbar will get to 100% if the installation of DownloadInternetFile.exe will take to long time.
If i have a good connection it will work perfect, but if i have a bad connection i get a error saying the statusbar value can not be more than 100%.
if (Install_DownloadInternetFile == "Yes")
{
if (File.Exists("DownloadInternetFile.exe"))
{
var DownloadInternetFile = Process.Start("DownloadInternetFile.exe", "/q /norestart");
while (!DownloadInternetFile.HasExited)
{
this.LoadBar.Value += 1;
await Task.Delay(TimeSpan.FromSeconds(2));
}
DownloadInternetFile.WaitForExit();
}
else
{
TopMost = false;
MessageBox.Show("DownloadInternetFile.exe not found", "Error");
}
}
else
{
MessageBox.Show("Notselect");
}
LoadBar.Value = 8;
// start DownloadInternetFile2
if (Install_DownloadInternetFile2 == "Yes")
{
if (File.Exists("DownloadInternetFile2.exe"))
{
var Dotnet45 = Process.Start("DownloadInternetFile2.exe", "/q");
while (!DownloadInternetFile2.HasExited)
{
this.LoadBar.Value += 1;
await Task.Delay(TimeSpan.FromSeconds(2));
}
DownloadInternetFile2.WaitForExit();
}
else
{
TopMost = false;
MessageBox.Show("DownloadInternetFile2.exe not found", "Error");
}
}
else
{
MessageBox.Show("Notselect");
}
LoadBar.Value = 10;
the code gones on with 10 more exe files installing. I think iam missing somthing in this part
this.LoadBar.Value += 1;
But can not figure it out
Upvotes: 0
Views: 91
Reputation: 190
By default the "Value" property of the "ProgressBar" class can be in the range of 0 to 100. Your code does not intrinsically know how much of the work has been done unless you calculate it. However, in your loop you make no calculation as to how much work has been done, but instead adjust the value of the progress bar based on time. So if you know your task is going to take the same amount of time, no matter what the conditions, this is an acceptable calculation. However if the time your actions takes can vary you'll need to find some other way to calculate the value of the progress bar that reflects the true progress of the action. For example, if your action is a download then your bar should reflect the bytes downloaded divided by the total bytes of the download.
Upvotes: 1