Ejemplo n.º 1
0
 internal void SponsorCallback(IAsyncResult iar)
 {
     if (this.state == LeaseState.Expired)
     {
         return;
     }
     if (Thread.CurrentThread.GetHashCode() == this.sponsorCallThread)
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback(this.SponsorCallback), (object)iar);
     }
     else
     {
         Lease.AsyncRenewal     asyncRenewal     = (Lease.AsyncRenewal)((AsyncResult)iar).AsyncDelegate;
         ISponsor               sponsor          = (ISponsor)asyncRenewal.Target;
         Lease.SponsorStateInfo sponsorStateInfo = (Lease.SponsorStateInfo)null;
         if (iar.IsCompleted)
         {
             bool     flag     = false;
             TimeSpan timeSpan = TimeSpan.Zero;
             try
             {
                 timeSpan = asyncRenewal.EndInvoke(iar);
             }
             catch (Exception ex)
             {
                 flag = true;
             }
             if (flag)
             {
                 this.Unregister(sponsor);
                 this.ProcessNextSponsor();
             }
             else
             {
                 object sponsorId = this.GetSponsorId(sponsor);
                 lock (this.sponsorTable)
                 {
                     if (this.sponsorTable.ContainsKey(sponsorId))
                     {
                         sponsorStateInfo = (Lease.SponsorStateInfo) this.sponsorTable[sponsorId];
                         sponsorStateInfo.sponsorState = Lease.SponsorState.Completed;
                         sponsorStateInfo.renewalTime  = timeSpan;
                     }
                 }
                 if (sponsorStateInfo == null)
                 {
                     this.ProcessNextSponsor();
                 }
                 else if (sponsorStateInfo.renewalTime == TimeSpan.Zero)
                 {
                     this.Unregister(sponsor);
                     this.ProcessNextSponsor();
                 }
                 else
                 {
                     this.RenewInternal(sponsorStateInfo.renewalTime);
                 }
             }
         }
         else
         {
             this.Unregister(sponsor);
             this.ProcessNextSponsor();
         }
     }
 }
Ejemplo n.º 2
0
        internal void SponsorCallback(IAsyncResult iar)
        {
            if (this.state == LeaseState.Expired)
            {
                return;
            }
            int hashCode = Thread.CurrentThread.GetHashCode();

            if (hashCode == this.sponsorCallThread)
            {
                WaitCallback callBack = new WaitCallback(this.SponsorCallback);
                ThreadPool.QueueUserWorkItem(callBack, iar);
                return;
            }
            AsyncResult asyncResult = (AsyncResult)iar;

            Lease.AsyncRenewal asyncRenewal = (Lease.AsyncRenewal)asyncResult.AsyncDelegate;
            ISponsor           sponsor      = (ISponsor)asyncRenewal.Target;

            Lease.SponsorStateInfo sponsorStateInfo = null;
            if (!iar.IsCompleted)
            {
                this.Unregister(sponsor);
                this.ProcessNextSponsor();
                return;
            }
            bool     flag        = false;
            TimeSpan renewalTime = TimeSpan.Zero;

            try
            {
                renewalTime = asyncRenewal.EndInvoke(iar);
            }
            catch (Exception)
            {
                flag = true;
            }
            if (flag)
            {
                this.Unregister(sponsor);
                this.ProcessNextSponsor();
                return;
            }
            object    sponsorId = this.GetSponsorId(sponsor);
            Hashtable obj       = this.sponsorTable;

            lock (obj)
            {
                if (this.sponsorTable.ContainsKey(sponsorId))
                {
                    sponsorStateInfo = (Lease.SponsorStateInfo) this.sponsorTable[sponsorId];
                    sponsorStateInfo.sponsorState = Lease.SponsorState.Completed;
                    sponsorStateInfo.renewalTime  = renewalTime;
                }
            }
            if (sponsorStateInfo == null)
            {
                this.ProcessNextSponsor();
                return;
            }
            if (sponsorStateInfo.renewalTime == TimeSpan.Zero)
            {
                this.Unregister(sponsor);
                this.ProcessNextSponsor();
                return;
            }
            this.RenewInternal(sponsorStateInfo.renewalTime);
        }