0

I have the following code:

        ProgressMessageHandler progress = new ProgressMessageHandler();
        progress.HttpSendProgress += new EventHandler<HttpProgressEventArgs>(HttpSendProgress);
        HttpRequestMessage message = new HttpRequestMessage();
        message.Method = HttpMethod.Post;
        message.Content = content;
        message.RequestUri = new Uri("http://myaddress");
        var client = HttpClientFactory.Create(progress);
        sending = client.SendAsync(message);


    private void HttpSendProgress(object sender, HttpProgressEventArgs e)
    {
         //....
    }

I want to catch a situation, when "myaddress" is not available. Method HttpSendProgress is called when progress is active, so, I can't check in this method. Any way to check if "myaddress" is available. I have an idea to start one more thread to check when HttpSendProgress is called last time. But maybe there is a standard method?

leppie
  • 115,091
  • 17
  • 196
  • 297
Oleg Sh
  • 8,496
  • 17
  • 89
  • 159

1 Answers1

0

I dont think you can check if the address is a working address in the progress event. You need to check the status after the response has come back.

    if (response.IsSuccessStatusCode)
    {
        Console.WriteLine(response.StatusCode.ToString());
    }

How to determine a 404 response status when using the HttpClient.GetAsync()

Community
  • 1
  • 1
Kallol
  • 264
  • 1
  • 12