0

I have a normal C# thread that calls a third party API (which internally makes a Network API call), recently I observed that sometimes the third party API throws WebTimeOut exception. My thread which calls the API is not running continuously, it is called only when needed (I cannot and do not wish to call the third party API from Main Thread).

This thread using that API is squaring-off an order and I must retry even if the Third Party API failed once/twice. How do I ensure that even if the thread had an exception (Like when calling that Third Party API which is throwing WebTimeOut Exception), it is retrying or restarting itself ?

1 Answers1

0

Why don't you use a try-catch statement inside the thread. When an exception is thrown, the exception will be handled in that catch statement. And then you can try to request the network api again.

try
{
    // Network API Call
}
catch (WebTimeOutException e)
{
    //...
}
catch (Exception e)
{
    //...
}
Alex
  • 1