internal async Task ConnectWithRetry()
{
while (true)
{
try
{
await ConnectToRedisAsync();
var oldState = Interlocked.CompareExchange(ref _state,
State.Connected,
State.Closed);
if (oldState == State.Closed)
{
OpenStream(0);
}
else
{
Debug.Assert(oldState == State.Disposing, "unexpected state");
Shutdown();
}
break;
}
catch (Exception ex)
{
_trace.TraceError("Error connecting to Redis - " + ex.GetBaseException());
}
if (_state == State.Disposing)
{
Shutdown();
break;
}
await Task.Delay(ReconnectDelay);
}
}