Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 184981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:23:21+00:00 2026-05-11T15:23:21+00:00

C# 2008 I have developed the class below. I have to get the balance

  • 0

C# 2008

I have developed the class below. I have to get the balance from the web server. Once that is done it will call back into my main app with the result.

However, sometime the web server fails for some unknown reason. Could be high volume of traffic or something else. However, I haven’t implemented any exception handling in my class. As the app that uses this handles the exception.

However, the client has confirmed that when the web server does fail it displays a unhandled exception dialog box. Then they have to click continue to keep using my application.

So below I am not sure if I should implement the exception handling in my class. However, I am confused as to why the exception was not caught in my app that as below.

Many thanks for any suggestions, or if you see anything else wrong,

private void OnGetBalanceCompleted(object sender, SIPPhoneLibraryEventArgs e)     {         try         {             //If the balance starts with 'null' there has been an error trying to get the balance.             if (e.Balance.StartsWith('null'))             {                 statusDisplay1.CurrentBalance = CATWinSIP_MsgStrings.BalanceError;             }             else             {                 // Display the current balance and round to 2 decimal places.                 statusDisplay1.CurrentBalance = Math.Round(Convert.ToDecimal(e.Balance), 2).ToString();                  //If the balance is zero display in the status message                 if (decimal.Parse(e.Balance) == 0)                 {                     this.statusDisplay1.CallStatus = 'Zero Balance';                 }             }             //Remove the event as no longer needed             siplibrary.GetBalanceCompletedEvent -= new EventHandler<SIPPhoneLibraryEventArgs>(OnGetBalanceCompleted);         }         catch (WebException ex)         {             MessageBox.Show(ex.Message);         }         catch (Exception ex)         {             MessageBox.Show(ex.Message);         }     }     //Control library for all importing functions public class Balance : IDisposable {     //Constructor     WebClient wc;     public Balance()     {         using (wc = new WebClient())         {             //Create event handler for the progress changed and download completed events             wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);             wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);         }     }      ~Balance()     {         this.Dispose(false);     }      //Event handler and the method that handlers the event     public EventHandler<SIPPhoneLibraryEventArgs> GetBalanceCompletedEvent;      //The method that raises the event     public void OnGetBalanceCompleted(SIPPhoneLibraryEventArgs e)     {         if (GetBalanceCompletedEvent != null)         {             GetBalanceCompletedEvent(this, e);         }     }      //Get the current balance for the user that is logged in.     //If the balance returned from the server is NULL display error to the user.     //Null could occur if the DB has been stopped or the server is down.            public void GetBalance(string sipUsername)     {         //Remove the underscore ( _ ) from the username, as this is not needed to get the balance.         sipUsername = sipUsername.Remove(0, 1);          string strURL = string.Format('http://xxx.xxx.xx.xx:xx/voipbilling/servlet/advcomm.voipbilling.GetBalance?CustomerID={0}', sipUsername);          //Download only when the webclient is not busy.         if (!wc.IsBusy)         {              // Sleep for 1/2 second to give the server time to update the balance.             System.Threading.Thread.Sleep(500);             // Download the current balance.             wc.DownloadStringAsync(new Uri(strURL));         }         else         {             System.Windows.Forms.MessageBox.Show('Busy please try again');         }     }      //return and display the balance after the download has fully completed     void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)     {         //Pass the result to the event handler         this.OnGetBalanceCompleted(new SIPPhoneLibraryEventArgs(e.Result));     }      //Progress state of balance.     void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)     {         //Write the details to the screen.         Console.WriteLine(e.TotalBytesToReceive);         Console.WriteLine(e.BytesReceived);         Console.WriteLine(e.ProgressPercentage);     }       //Dispose of the balance object     public void Dispose()     {         Dispose(true);          GC.SuppressFinalize(this);     }      //Remove the event handlers     private bool isDisposed = false;     private void Dispose(bool disposing)     {         if (!this.isDisposed)         {             if (disposing)             {                 wc.DownloadProgressChanged -= new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);                 wc.DownloadStringCompleted -= new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);                  wc.Dispose();             }                            isDisposed = true;         }     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:23:22+00:00Added an answer on May 11, 2026 at 3:23 pm

    It seems that you are catching the exception on the OnGetBalanceCompleted event only, instead on the process of fetching the balance.

    When there is any error on the fetching, the OnGetBalanceCompleted is not even called, that’s why your exception handler is not called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple windows Service that is developed in vb.net 2008. When
I have developed an application using VB.NET, Visual Studio 2008 and the SQL Server
Background: I have a .NET 4.0 web service running on Windows Server 2008 written
I have developed a servlet and deployed it on my server -windows server 2008-
I have developed application in VS 2008 and trying to host on godaddy server
I have developed an application that have a slider that showing some data from
We have developed an assembly for SQL Server 2008 R2. The assembly has been
I have developed a Windows service using Visual Studio 2008. I want to install
I have an application developed with Visual Studio 2008 and distributed throught ClickOnce. My
I developed a WinForms application (using C#, with visual studio 2008) and I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.