protected override void RefreshToken() { try { _traceSource.TraceInformation("\nBrowserBasedTokenRetriever checking cache"); _token = _cache?.LoadFromCache(); if (_token != null) { SetExpireDateFromToken(); } } catch { ClearAllCacheInformation(); } if (string.IsNullOrEmpty(_token) || IsExpiredOrAboutToExpire) { _traceSource.TraceInformation("\nStarted retrieving token from BrowserBasedTokenRetriever using {0}.", AuthenticationEndpoint); ClearAllCacheInformation(); try { string stsToken = null; string issuingAuthority = ConfigItems["v2.FcsaIssuingAuthority"]; var securityContextRetreiver = new Thread(() => { Thread.CurrentThread.IsBackground = true; using (var t = new BrowserTokenRetriever(AuthenticationEndpoint, issuingAuthority)) { stsToken = t.RetrieveToken(); } }); securityContextRetreiver.SetApartmentState(ApartmentState.STA); securityContextRetreiver.Start(); securityContextRetreiver.Join(DefaultTimeoutInMiliSeconds); _token = !string.IsNullOrEmpty(stsToken) ? CleanToken(stsToken) : stsToken; _cache?.SaveToCache(_token); _traceSource.TraceInformation("\nCompleted retrieving token from BrowerBasedTokenRetriever."); } catch (Exception ex) { _traceSource.TraceEvent(TraceEventType.Error, 0, "\nException occured during TokenRetriever RetrieveToken.\n" + UnwrapException(ex).ToString()); } SetExpireDateFromToken(); } }