1

This is a continuation of my previous question: Download file in chunks

Right now, I have a working application, that allows to download and play large media files. However, there's still a problem left. As I've noticed, if the download time is more than five minutes, the connection is closed, because of timeout. That's not a problem, because the app can easily reopen it, send another request, e.t.c.

Now, that's a problem: There can be several types of errors with the response, but I can't divide the "timeout expired" exception(if I catch this one, I use the method, that will continue downloading) from the other exceptions, that are really caused by errors. They all have type of WebException. I also tried the solution from this article, but the ex.Status value is "unknown error"(!). The message value is also equal "The remote server returned an error: NotFound."

So, my question is simple: how to define that the error is caused by timeout?

Community
  • 1
  • 1
Olter
  • 1,129
  • 1
  • 21
  • 40

1 Answers1

1

Possible solution:

The type of WebException can be defined this way:

 catch (WebException ex)
            {
              HttpWebResponse response = (HttpWebResponse)ex.Response;

              if (response.StatusCode == HttpStatusCode.someCode)
                    DoSomething();
            }

So, in my case, the HttpStatusCode will be "Forbidden" (error 403). Using this info I can create the future logic.

Olter
  • 1,129
  • 1
  • 21
  • 40