none
progress bar for .GetResponse() method of HttpWebRequest class RRS feed

  • Question


  • I need to show progress bar for the below code. Can I have a progressbar of ".GetResponse()" method of HttpWebRequest

     private static HttpWebResponse GetRawResponse(HttpWebRequest request)
        {
            try
            {
                return (HttpWebResponse)request.GetResponse();
            }
            catch (WebException ex)
            {
                if (ex.Response is HttpWebResponse)
                {
                    return ex.Response as HttpWebResponse;
                }
                throw;
            }
        }

    Thanks

    Sujit


    sujit

    Monday, March 18, 2013 10:56 AM

Answers

  • If you can use some estimate between reponse and file size and how long getting response might take with the file that is uploaded, then you can use BackgroundWorker to invoke the GetResponse and use Timer to calculate how much time has passed from your estimate.

    You can see how to use BackgroundWorker like http://www.codeproject.com/Articles/99143/BackgroundWorker-Class-Sample-for-Beginners

    But still I might use just busy indicator because estimating the times might vary depending on multiple factors other than just the file size, and your calculations might be wrong in big time.

    Or use just different way to upload file where you send chunks of the file and show how much you have send from the total.

    Tuesday, March 19, 2013 12:40 PM

All replies

  • You might just want to show that application is busy like with spinning cursor unless you want to use time as progress because that's just about all it takes.

    After you actually have the response then it might be more useful to show progress bar when you process the response, if needed.

    • Proposed as answer by Mike FengModerator Tuesday, March 19, 2013 11:48 AM
    • Unproposed as answer by sujit1779 Tuesday, March 19, 2013 12:15 PM
    Monday, March 18, 2013 2:09 PM
  • Hi,

    What you are saying is to show a busy cursor, which isn't the case for me. My upload takes sometimes 10 mins or more depending upon the file length, so I need to show progress percentage.

    Thanks.


    sujit

    Tuesday, March 19, 2013 12:15 PM
  • If you can use some estimate between reponse and file size and how long getting response might take with the file that is uploaded, then you can use BackgroundWorker to invoke the GetResponse and use Timer to calculate how much time has passed from your estimate.

    You can see how to use BackgroundWorker like http://www.codeproject.com/Articles/99143/BackgroundWorker-Class-Sample-for-Beginners

    But still I might use just busy indicator because estimating the times might vary depending on multiple factors other than just the file size, and your calculations might be wrong in big time.

    Or use just different way to upload file where you send chunks of the file and show how much you have send from the total.

    Tuesday, March 19, 2013 12:40 PM