Note that there are some explanatory texts on larger screens.

plurals
  1. POEvent to find when internet is lost
    text
    copied!<p>I am creating a windows application using C#. It is used to check whether any updated version of a product is available or not. If yes, the user can download it using the application's UI only without opening any browser.</p> <p>One window in the application displays the status of the download using ProgressBar control. The problem is, in case the internet gets disconnected, the application does not come to know. Say, after 45% of the download, the network disconnects; but the ProgressBar keeps on displaying 45%.</p> <p>Is there any property/event that is raised once such situation occurs? Please help. Attaching my code as well for your reference. Thanks.</p> <pre><code>private void CheckForUpdate_Load(object sender, EventArgs e) { string downloadURL = Convert.ToString(ConfigurationManager.AppSettings["TempDownloadURL"]); WebClient wcDownloadFile = new WebClient(); Uri myUri = new Uri(downloadURL); wcDownloadFile.DownloadFileAsync(myUri, downloadLocation); wcDownloadFile.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wcDownloadFile_DownloadProgressChanged); } void wcDownloadFile_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { try { int bytesDownloaded = Int32.Parse(e.BytesReceived.ToString()); int totalBytes = Int32.Parse(e.TotalBytesToReceive.ToString()); progBarSoftPhone.Value = e.ProgressPercentage; lblStatus.Text = (bytesDownloaded / 1024).ToString() + " KB out of " + (totalBytes / 1024).ToString() + " KB downloaded (" + e.ProgressPercentage.ToString() + "%)."; } catch (Exception ex) { MessageBox.Show("ERROR: " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload