Count time spent upwards to display attempts correctly

This commit is contained in:
Salman Ahmed 2022-07-02 10:46:52 +03:00
parent 93809a92d4
commit e28ee8bc7a
1 changed files with 4 additions and 4 deletions

View File

@ -849,7 +849,7 @@ public IDisposable BlockAllOperations(string reason)
Logger.Log(@"Lock acquired for blocking operations", LoggingTarget.Database);
const int sleep_length = 200;
int timeout = 5000;
int timeSpent = 0;
try
{
@ -857,10 +857,10 @@ public IDisposable BlockAllOperations(string reason)
while (!Compact())
{
Thread.Sleep(sleep_length);
timeout -= sleep_length;
timeSpent += sleep_length;
if (timeout < 0)
throw new TimeoutException($@"Realm compact failed after {timeout / sleep_length} attempts over {timeout / 1000} seconds");
if (timeSpent > 5000)
throw new TimeoutException($@"Realm compact failed after {timeSpent / sleep_length} attempts over {timeSpent / 1000} seconds");
}
}
catch (RealmException e)