I'm very new to C# coding and I just want to know how to setup polly WaitAndRetry for my function if it failed. Following is my steps
- I installed package Install-Package Polly, using NuGet package
- added using polly in my code.
- Below is my code
public async Task<string> ConfigInsert(config model)
{
try
{
SendToDatabase(model);
await Policy.Handle<Exception>()
.RetryAsync(NUMBER_OF_RETRIES)
.ExecuteAsync(async () =>
await SendToDatabase(model))
.ConfigureAwait(false);
}
Catch(Exception e)
{
_log.write("error occurred");
}
public async Task<string> SendToDataBase(config model)
{
var ss = DataBase.PostCallAsync(model)
.GetAwaiter()
.GetResult();
return ss;
}
}
But this call is continuously calling without any delay. I tried to use WaitAndRetryAsync in catch call but it's not working. WaitAndRetryAsync accepts only HTTP repose message. I want to implement ait and retry option in try-catch