Fix multiple requests potentially being triggered during connect sequence

As the Success callbacks happen in a scheduled context, if the Update thread is in a stalled state, this loop can generate many unnecessary API requests.
This commit is contained in:
Dean Herbert 2017-10-24 17:13:59 +09:00
parent 65d1594be8
commit 808c97fcb4
1 changed files with 12 additions and 2 deletions

View File

@ -121,18 +121,28 @@ private void run()
continue;
}
var userReq = new GetUserRequest();
userReq.Success += u =>
{
LocalUser.Value = u;
failureCount = 0;
//we're connected!
State = APIState.Online;
failureCount = 0;
};
if (!handleRequest(userReq))
{
Thread.Sleep(500);
continue;
}
// The Success callback event is fired on the main thread, so we should wait for that to run before proceeding.
// Without this, we will end up circulating this Connecting loop multiple times and queueing up many web requests
// before actually going online.
while (State != APIState.Online)
Thread.Sleep(500);
break;
}