This is the code of the connection testing of the internet while downloading the file in the contrustor:
Expand|Select|Wrap|Line Numbers
- if (fdt.http_test()== true)
- {
- Client.DownloadFile(remote_image_on_server, temp_dir + temp_file);
- label6.Enabled = true;
- label6.Visible = true;
- label6.Text = "Internet connection active";
- }
- else
- {
- Logger.Write("Connection to the internet has failed");
- button1.Enabled = true;
- timer1.Enabled = false;
- label6.Enabled = true;
- label6.Visible = true;
- }
Expand|Select|Wrap|Line Numbers
- Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Client_DownloadFileCompleted);
And i added this line to the internet connection checking after this line Client.DownloadFile(remote_image_on_server, temp_dir + temp_file);
So it looks like:
Expand|Select|Wrap|Line Numbers
- if (fdt.http_test()== true)
- {
- Client.DownloadFile(remote_image_on_server, temp_dir + temp_file);
- Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Client_DownloadFileCompleted);
- label6.Enabled = true;
- label6.Visible = true;
- label6.Text = "Internet connection active";
- }
Expand|Select|Wrap|Line Numbers
- private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
- {
- MessageBox.Show("file downloaded in: ");
- }
What did i do wrong? Or how should i do it so it will show something like " The file have been downloaded in: 3 seconds " ?
Thanks.
Ok i found how to make the event to be raised.
I added this two files in the constructor to the code i showed above:
Expand|Select|Wrap|Line Numbers
- Client.DownloadFileCompleted +=
- new AsyncCompletedEventHandler(Client_DownloadFileCompleted);
- Client.DownloadFileAsync(new Uri(satellite_address), temp_dir + satellite_file_name);
The problem is how do i make the application in the constructor to wait for the event to be raised before it continue?
Cuz i used breakpoint on this lines and its continue on the constructor and only when the application is finished loading im getting the messagebox of the event. I want to get the messagebox of the event before the application is loaded. When it start to download so it will wait raise the event tell me its finished and only then continue loading the rest of the application in the constructor.
How can i do it?