internal int GetMemberCount(IConfigurationSession session, ExDateTime now, int quota) { int result = 0; this.ThrowAnySavedExceptionsFromAsyncThreads(); try { if (!this.cachedCountLock.TryEnterReadLock(SystemAddressListMemberCountCacheValue.readerLockTimeout)) { throw new TransientException(DirectoryStrings.ErrorTimeoutReadingSystemAddressListMemberCount); } if (this.systemAddressListExists && this.lastQueriedTime + this.lifetime < now) { SystemAddressListMemberCountCacheValue.UpdateInfo updateInfo = new SystemAddressListMemberCountCacheValue.UpdateInfo(session, now, quota); this.StartAsyncUpdate(updateInfo); } result = this.memberCount; } finally { try { this.cachedCountLock.ExitReadLock(); } catch (SynchronizationLockException) { } } return(result); }
internal int InitializeMemberCount(IConfigurationSession session, ExDateTime now, int quota) { try { if (!this.cachedCountLock.TryEnterReadLock(SystemAddressListMemberCountCacheValue.readerLockTimeout)) { throw new TransientException(DirectoryStrings.ErrorTimeoutReadingSystemAddressListMemberCount); } if (!this.systemAddressListExists) { return(0); } } finally { try { this.cachedCountLock.ExitReadLock(); } catch (SynchronizationLockException) { } } SystemAddressListMemberCountCacheValue.UpdateInfo o = new SystemAddressListMemberCountCacheValue.UpdateInfo(session, now, quota); Interlocked.Increment(ref this.asyncUpdatesInProgress); this.UpdateMemberCount(o); this.ThrowAnySavedExceptionsFromAsyncThreads(); return(this.memberCount); }
private void StartAsyncUpdate(SystemAddressListMemberCountCacheValue.UpdateInfo updateInfo) { if (this.asyncUpdatesInProgress == 0) { Interlocked.Increment(ref this.asyncUpdatesInProgress); ThreadPool.QueueUserWorkItem(new WaitCallback(this.UpdateMemberCount), updateInfo); } }
private void UpdateMemberCount(object o) { try { SystemAddressListMemberCountCacheValue.UpdateInfo updateInfo = (SystemAddressListMemberCountCacheValue.UpdateInfo)o; Exception ex = null; int num = 0; try { num = AddressBookBase.GetAddressListSize(updateInfo.Session, this.systemAddressListGuid); } catch (Exception ex2) { ex = ex2; } try { this.cachedCountLock.EnterWriteLock(); if (ex != null) { this.asyncException = ex; } else if (num == -1) { this.systemAddressListExists = false; this.memberCount = 0; this.lastQueriedTime = updateInfo.Now; this.lifetime = TimeSpan.MaxValue; } else { this.memberCount = num; this.lastQueriedTime = updateInfo.Now; this.lifetime = this.CalculateValidLifetime(updateInfo.Quota); } } finally { try { this.cachedCountLock.ExitWriteLock(); } catch (SynchronizationLockException) { } } } finally { Interlocked.Decrement(ref this.asyncUpdatesInProgress); } }