Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using async functions from synchronous code #302

Open
wants to merge 1 commit into
base: dev1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions src/CacheManager.StackExchange.Redis/RetryHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Threading.Tasks;
using System.Threading;
using CacheManager.Core.Logging;
using StackExchange.Redis;

Expand Down Expand Up @@ -37,11 +37,7 @@ public static T Retry<T>(Func<T> retryme, int timeOut, int retries, ILogger logg
}

logger.LogWarn(ex, WarningMessage, tries, retries);
#if NET40
TaskEx.Delay(timeOut).Wait();
#else
Task.Delay(timeOut).Wait();
#endif
Thread.Sleep(timeOut);
}
catch (RedisConnectionException ex)
{
Expand All @@ -52,11 +48,7 @@ public static T Retry<T>(Func<T> retryme, int timeOut, int retries, ILogger logg
}

logger.LogWarn(ex, WarningMessage, tries, retries);
#if NET40
TaskEx.Delay(timeOut).Wait();
#else
Task.Delay(timeOut).Wait();
#endif
Thread.Sleep(timeOut);
}
catch (TimeoutException ex)
{
Expand All @@ -67,11 +59,7 @@ public static T Retry<T>(Func<T> retryme, int timeOut, int retries, ILogger logg
}

logger.LogWarn(ex, WarningMessage, tries, retries);
#if NET40
TaskEx.Delay(timeOut).Wait();
#else
Task.Delay(timeOut).Wait();
#endif
Thread.Sleep(timeOut);
}
catch (AggregateException aggregateException)
{
Expand All @@ -91,11 +79,7 @@ public static T Retry<T>(Func<T> retryme, int timeOut, int retries, ILogger logg
if (e is RedisConnectionException || e is System.TimeoutException || e is RedisServerException)
{
logger.LogWarn(e, WarningMessage, tries, retries);
#if NET40
TaskEx.Delay(timeOut).Wait();
#else
Task.Delay(timeOut).Wait();
#endif
Thread.Sleep(timeOut);

return true;
}
Expand Down Expand Up @@ -123,4 +107,4 @@ public static void Retry(Action retryme, int timeOut, int retries, ILogger logge
logger);
}
}
}
}