diff --git a/Blish HUD/GameServices/Gw2WebApiService.cs b/Blish HUD/GameServices/Gw2WebApiService.cs index b5152b78d..c1f1d23ab 100644 --- a/Blish HUD/GameServices/Gw2WebApiService.cs +++ b/Blish HUD/GameServices/Gw2WebApiService.cs @@ -111,7 +111,7 @@ private async Task UpdateActiveApiKey() { private async void PlayerCharacterOnNameChanged(object sender, ValueEventArgs e) { if (!_characterRepository.ContainsKey(e.Value)) { // We don't currently have an API key associated to this character so we double-check the characters on each key - await RefreshRegisteredKeys (); + await RefreshRegisteredKeys(); } else { await UpdateActiveApiKey(); } @@ -213,7 +213,20 @@ public ManagedConnection GetConnection(string accessToken) { protected override void Unload() { /* NOOP */ } - protected override void Update(GameTime gameTime) { /* NOOP */ } + private double _checkFrequency = 0; + + protected override void Update(GameTime gameTime) { + _checkFrequency += gameTime.ElapsedGameTime.TotalMilliseconds; + + if (_checkFrequency > 180000) { + _checkFrequency = 0; + + if (string.IsNullOrEmpty(PrivilegedConnection.Connection.AccessToken)) { + RefreshRegisteredKeys(); + } + } + + } } } \ No newline at end of file diff --git a/Blish HUD/GameServices/Modules/Managers/Gw2ApiManager.cs b/Blish HUD/GameServices/Modules/Managers/Gw2ApiManager.cs index 20ad91546..ca377ddc6 100644 --- a/Blish HUD/GameServices/Modules/Managers/Gw2ApiManager.cs +++ b/Blish HUD/GameServices/Modules/Managers/Gw2ApiManager.cs @@ -18,7 +18,13 @@ public class Gw2ApiManager { private static readonly List _apiManagers = new List(); internal static async Task RenewAllSubtokens() { - foreach (var apiManager in _apiManagers) { + Gw2ApiManager[] apiManagers; + + lock(_apiManagers) { + apiManagers = _apiManagers.ToArray(); + } + + foreach (var apiManager in apiManagers) { await apiManager.RenewSubtoken(); } } @@ -38,7 +44,9 @@ internal static async Task RenewAllSubtokens() { public List Permissions => _permissions.ToList(); private Gw2ApiManager(IEnumerable permissions, ManagedConnection moduleConnection) { - _apiManagers.Add(this); + lock (_apiManagers) { + _apiManagers.Add(this); + } _permissions = permissions.ToHashSet(); _activePermissions = new HashSet();