This is the async download code:
private void fileDownloadRadar()<br/>
{<br/>
if (Client.IsBusy == true)<br/>
{<br/>
Client.CancelAsync();<br/>
}<br/>
else<br/>
{<br/>
Client.DownloadFileAsync(myUri, Path.Combine(temp_dir + temp_file));<br/>
}<br/>
}
And in the <span style="font-family:Consolas; color:#0000ff; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small private<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small void<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
Client_DownloadFileCompleted(<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small object<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
sender, <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small AsyncCompletedEventArgs<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
e)
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small I have
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
if
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small (e.Error !=
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small null<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small )
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small {
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small }
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small Wich is empty now. Inside this e.Error i want to make that for example if fore some reason the internet disconnected or the site crashed and he try
to download he will get to the e.Error wich is what hapening now.
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small But when its getting to the e.Error i want it will try to make download like 5-10 times one after one straiht away then if after 5-10 times it didnt
success the timer will be reseted to what the user entered before as download time.
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small The thing is when the program is up the user can set the time that it will download each file. For exampe if the user enter 30 it will download the
next file every 30 seconds.
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small So i want in the e.Error it will try to download 5-10 times one after one without waiting 30 seconds between them and if it didnt success it will
be reset to 30 seconds again as the user requested in the begining.
<span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small This is the code of the timer where the user enter first time the time in seconds:
<span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small private void timer1_Tick(object sender, EventArgs e)<br/>
{<br/>
try<br/>
{<br/>
numbers = Convert.ToInt64(textBox1.Text);<br/>
if (numbers <= 0)<br/>
{<br/>
timer1.Stop();<br/>
button1.Enabled = true;<br/>
textBox1.Enabled = true;<br/>
MessageBox.Show("Value cannot be zero or below zero");<br/>
textBox1.Text = "";<br/>
}<br/>
else<br/>
{<br/>
Numbers_Timer = Numbers_Timer + 1;
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small if (Numbers_Timer >= numbers)<br/>
{<br/>
try<br/>
{<br/>
filesdownload();<br/>
number_of_files_in_current_directory = Directory.GetFiles(sf, "radar*.jpg");<br/>
label8.Text = "Current Number Of Files In The Selected Directory Are: " + number_of_files_in_current_directory.Length;<br/>
button1.Enabled = false;<br/>
Numbers_Timer = 0;<br/>
}<br/>
catch (Exception Local_Timer1_Exceptions)<br/>
{<br/>
Logger.Write("Timer1 Errors : " + Local_Timer1_Exceptions);<br/>
}<br/>
}<br/>
time_left = numbers - Numbers_Timer;<br/>
label1.Text = "Time left for the next radar image to be download: " + time_left;<br/>
}
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small }<br/>
catch (Exception General_Exceptions)<br/>
{<br/>
Logger.Write("Show if numbers have wrong string input" + numbers);<br/>
timer1.Stop();<br/>
Logger.Write("Exception: " + General_Exceptions + Environment.NewLine);<br/>
textBox1.Clear();<br/>
button1.Enabled = true;<br/>
textBox1.Enabled = true;<br/>
Numbers_Timer = 0;<br/>
}
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small }
<span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small And filesdownload(); is the download async function as i said above its calling:
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small fileDownloadRadar();
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small Thanks for help.
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<hr class="sig danieli
View the full article
private void fileDownloadRadar()<br/>
{<br/>
if (Client.IsBusy == true)<br/>
{<br/>
Client.CancelAsync();<br/>
}<br/>
else<br/>
{<br/>
Client.DownloadFileAsync(myUri, Path.Combine(temp_dir + temp_file));<br/>
}<br/>
}
And in the <span style="font-family:Consolas; color:#0000ff; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small private<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small void<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
Client_DownloadFileCompleted(<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small object<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
sender, <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small AsyncCompletedEventArgs<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
e)
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small I have
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
if
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small (e.Error !=
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small null<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small )
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small {
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small }
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small Wich is empty now. Inside this e.Error i want to make that for example if fore some reason the internet disconnected or the site crashed and he try
to download he will get to the e.Error wich is what hapening now.
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small But when its getting to the e.Error i want it will try to make download like 5-10 times one after one straiht away then if after 5-10 times it didnt
success the timer will be reseted to what the user entered before as download time.
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small The thing is when the program is up the user can set the time that it will download each file. For exampe if the user enter 30 it will download the
next file every 30 seconds.
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small So i want in the e.Error it will try to download 5-10 times one after one without waiting 30 seconds between them and if it didnt success it will
be reset to 30 seconds again as the user requested in the begining.
<span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small This is the code of the timer where the user enter first time the time in seconds:
<span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small private void timer1_Tick(object sender, EventArgs e)<br/>
{<br/>
try<br/>
{<br/>
numbers = Convert.ToInt64(textBox1.Text);<br/>
if (numbers <= 0)<br/>
{<br/>
timer1.Stop();<br/>
button1.Enabled = true;<br/>
textBox1.Enabled = true;<br/>
MessageBox.Show("Value cannot be zero or below zero");<br/>
textBox1.Text = "";<br/>
}<br/>
else<br/>
{<br/>
Numbers_Timer = Numbers_Timer + 1;
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small if (Numbers_Timer >= numbers)<br/>
{<br/>
try<br/>
{<br/>
filesdownload();<br/>
number_of_files_in_current_directory = Directory.GetFiles(sf, "radar*.jpg");<br/>
label8.Text = "Current Number Of Files In The Selected Directory Are: " + number_of_files_in_current_directory.Length;<br/>
button1.Enabled = false;<br/>
Numbers_Timer = 0;<br/>
}<br/>
catch (Exception Local_Timer1_Exceptions)<br/>
{<br/>
Logger.Write("Timer1 Errors : " + Local_Timer1_Exceptions);<br/>
}<br/>
}<br/>
time_left = numbers - Numbers_Timer;<br/>
label1.Text = "Time left for the next radar image to be download: " + time_left;<br/>
}
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small }<br/>
catch (Exception General_Exceptions)<br/>
{<br/>
Logger.Write("Show if numbers have wrong string input" + numbers);<br/>
timer1.Stop();<br/>
Logger.Write("Exception: " + General_Exceptions + Environment.NewLine);<br/>
textBox1.Clear();<br/>
button1.Enabled = true;<br/>
textBox1.Enabled = true;<br/>
Numbers_Timer = 0;<br/>
}
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small }
<span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small And filesdownload(); is the download async function as i said above its calling:
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small fileDownloadRadar();
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small Thanks for help.
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<hr class="sig danieli
View the full article