1

I have a little C# project it send unique data with WebRequest on an internet site and get back a HttpWebResponse. Now I want to handle the situation with no internet connection or other thinks the data could not send or receive.

In my opinion its the best way to handle that with the Webexception in try/catch.

But its important on a Webexception, the program remember the action and try it again if the internet or the service is reachable again.

What is the best way in your opinion to realize that?

I read about Queue... Maybe to put the action in the Queue if Webexception will throw and try it again if Service is reachable again?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Denis
  • 439
  • 4
  • 17

3 Answers3

0

Timer should work. When an exception is being thrown, reset the timer. When the interval occurs you can try to connect again

Sievajet
  • 3,443
  • 2
  • 18
  • 22
0

I think that a simple way is create a loop to call a boolean method, if inside this of this occurs an exception returns false and the loop continues

Ignacio Laborde
  • 1,442
  • 2
  • 11
  • 10
0

@Denis I found this question interesting and I had a go at it.

https://dotnetfiddle.net/2lx8FI

  • Push-based queue by converting a List<string> to an IObservable sequence. Thread.Sleep controls how often an item is read from the queue.
  • In case of WebException, we wait for "a while" and add the URL back to List<string>
  • Reading URLs from user input is just for testing purposes.

I hope it helps

supertopi
  • 3,469
  • 26
  • 38