internal void SponsorCall(ISponsor sponsor) { bool flag = false; if (this.state != LeaseState.Expired) { lock (this.sponsorTable) { try { object sponsorId = this.GetSponsorId(sponsor); this.sponsorCallThread = Thread.CurrentThread.GetHashCode(); AsyncRenewal renewal = new AsyncRenewal(sponsor.Renewal); SponsorStateInfo info = (SponsorStateInfo)this.sponsorTable[sponsorId]; info.sponsorState = SponsorState.Waiting; renewal.BeginInvoke(this, new AsyncCallback(this.SponsorCallback), null); if ((info.sponsorState == SponsorState.Waiting) && (this.state != LeaseState.Expired)) { this.leaseManager.RegisterSponsorCall(this, sponsorId, this.sponsorshipTimeout); } this.sponsorCallThread = 0; } catch (Exception) { flag = true; this.sponsorCallThread = 0; } } if (flag) { this.Unregister(sponsor); this.ProcessNextSponsor(); } } }
internal void SponsorCall(ISponsor sponsor) { BCLDebug.Trace("REMOTE", "Lease ", id, " SponsorCall state ", ((Enum)state).ToString()); bool exceptionOccurred = false; if (state == LeaseState.Expired) { return; } lock (sponsorTable) { try { Object sponsorId = GetSponsorId(sponsor); sponsorCallThread = Thread.CurrentThread.GetHashCode(); AsyncRenewal ar = new AsyncRenewal(sponsor.Renewal); SponsorStateInfo sponsorStateInfo = (SponsorStateInfo)sponsorTable[sponsorId]; sponsorStateInfo.sponsorState = SponsorState.Waiting; // The first parameter should be the lease we are trying to renew. IAsyncResult iar = ar.BeginInvoke(this, new AsyncCallback(this.SponsorCallback), null); if ((sponsorStateInfo.sponsorState == SponsorState.Waiting) && (state != LeaseState.Expired)) { // Even if we get here, the operation could still complete before // we call the the line below. This seems to be a race. // Sponsor could have completed before statement is reached, so only execute // if the sponsor state is still waiting leaseManager.RegisterSponsorCall(this, sponsorId, sponsorshipTimeout); } sponsorCallThread = 0; }catch (Exception) { // Sponsor not avaiable exceptionOccurred = true; sponsorCallThread = 0; } } if (exceptionOccurred) { BCLDebug.Trace("REMOTE", "Lease ", id, " SponsorCall Sponsor Exception "); Unregister(sponsor); ProcessNextSponsor(); } }
// On another thread internal void SponsorCallback(IAsyncResult iar) { BCLDebug.Trace("REMOTE", "Lease ", id, " SponsorCallback IAsyncResult ", iar, " state ", ((Enum)state).ToString()); if (state == LeaseState.Expired) { return; } int thisThread = Thread.CurrentThread.GetHashCode(); if (thisThread == sponsorCallThread) { WaitCallback threadFunc = new WaitCallback(this.SponsorCallback); ThreadPool.QueueUserWorkItem(threadFunc, iar); return; } AsyncResult asyncResult = (AsyncResult)iar; AsyncRenewal ar = (AsyncRenewal)asyncResult.AsyncDelegate; ISponsor sponsor = (ISponsor)ar.Target; SponsorStateInfo sponsorStateInfo = null; if (iar.IsCompleted) { // Sponsor came back with renewal BCLDebug.Trace("REMOTE", "Lease ", id, " SponsorCallback sponsor completed"); bool exceptionOccurred = false; TimeSpan renewalTime = TimeSpan.Zero; try { renewalTime = (TimeSpan)ar.EndInvoke(iar); }catch (Exception) { // Sponsor not avaiable exceptionOccurred = true; } if (exceptionOccurred) { BCLDebug.Trace("REMOTE", "Lease ", id, " SponsorCallback Sponsor Exception "); Unregister(sponsor); ProcessNextSponsor(); } else { Object sponsorId = GetSponsorId(sponsor); lock (sponsorTable) { if (sponsorTable.ContainsKey(sponsorId)) { sponsorStateInfo = (SponsorStateInfo)sponsorTable[sponsorId]; sponsorStateInfo.sponsorState = SponsorState.Completed; sponsorStateInfo.renewalTime = renewalTime; } else { // Sponsor was deleted, possibly from a sponsor time out } } if (sponsorStateInfo == null) { // Sponsor was deleted ProcessNextSponsor(); } else if (sponsorStateInfo.renewalTime == TimeSpan.Zero) { BCLDebug.Trace("REMOTE", "Lease ", id, " SponsorCallback sponsor did not renew "); Unregister(sponsor); ProcessNextSponsor(); } else { Renew(sponsorStateInfo.renewalTime); } } } else { // Sponsor timed out // Note time outs should be handled by the LeaseManager BCLDebug.Trace("REMOTE", "Lease ", id, " SponsorCallback sponsor did not complete, timed out"); Unregister(sponsor); ProcessNextSponsor(); } }
internal void SponsorCallback(IAsyncResult iar) { if (this.state != LeaseState.Expired) { if (Thread.CurrentThread.GetHashCode() == this.sponsorCallThread) { WaitCallback callBack = new WaitCallback(this.SponsorCallback); ThreadPool.QueueUserWorkItem(callBack, iar); } else { AsyncResult result = (AsyncResult)iar; AsyncRenewal asyncDelegate = (AsyncRenewal)result.AsyncDelegate; ISponsor target = (ISponsor)asyncDelegate.Target; SponsorStateInfo info = null; if (iar.IsCompleted) { bool flag = false; TimeSpan zero = TimeSpan.Zero; try { zero = asyncDelegate.EndInvoke(iar); } catch (Exception) { flag = true; } if (flag) { this.Unregister(target); this.ProcessNextSponsor(); } else { object sponsorId = this.GetSponsorId(target); lock (this.sponsorTable) { if (this.sponsorTable.ContainsKey(sponsorId)) { info = (SponsorStateInfo)this.sponsorTable[sponsorId]; info.sponsorState = SponsorState.Completed; info.renewalTime = zero; } } if (info == null) { this.ProcessNextSponsor(); } else if (info.renewalTime == TimeSpan.Zero) { this.Unregister(target); this.ProcessNextSponsor(); } else { this.RenewInternal(info.renewalTime); } } } else { this.Unregister(target); this.ProcessNextSponsor(); } } } }
internal void SponsorCall(ISponsor sponsor) { bool flag = false; if (this.state != LeaseState.Expired) { lock (this.sponsorTable) { try { object sponsorId = this.GetSponsorId(sponsor); this.sponsorCallThread = Thread.CurrentThread.GetHashCode(); AsyncRenewal renewal = new AsyncRenewal(sponsor.Renewal); SponsorStateInfo info = (SponsorStateInfo) this.sponsorTable[sponsorId]; info.sponsorState = SponsorState.Waiting; renewal.BeginInvoke(this, new AsyncCallback(this.SponsorCallback), null); if ((info.sponsorState == SponsorState.Waiting) && (this.state != LeaseState.Expired)) { this.leaseManager.RegisterSponsorCall(this, sponsorId, this.sponsorshipTimeout); } this.sponsorCallThread = 0; } catch (Exception) { flag = true; this.sponsorCallThread = 0; } } if (flag) { this.Unregister(sponsor); this.ProcessNextSponsor(); } } }
[System.Security.SecurityCritical] // auto-generated internal void SponsorCall(ISponsor sponsor) { BCLDebug.Trace("REMOTE","Lease ",id," SponsorCall state ",((Enum)state).ToString()); bool exceptionOccurred = false; if (state == LeaseState.Expired) return; lock(sponsorTable) { try { Object sponsorId = GetSponsorId(sponsor); sponsorCallThread = Thread.CurrentThread.GetHashCode(); AsyncRenewal ar = new AsyncRenewal(sponsor.Renewal); SponsorStateInfo sponsorStateInfo = (SponsorStateInfo)sponsorTable[sponsorId]; sponsorStateInfo.sponsorState = SponsorState.Waiting; // The first parameter should be the lease we are trying to renew. IAsyncResult iar = ar.BeginInvoke(this, new AsyncCallback(this.SponsorCallback), null); if ((sponsorStateInfo.sponsorState == SponsorState.Waiting) && (state != LeaseState.Expired)) { // Even if we get here, the operation could still complete before // we call the the line below. This seems to be a ----. // Sponsor could have completed before statement is reached, so only execute // if the sponsor state is still waiting leaseManager.RegisterSponsorCall(this, sponsorId, sponsorshipTimeout); } sponsorCallThread = 0; }catch(Exception) { // Sponsor not avaiable exceptionOccurred = true; sponsorCallThread = 0; } } if (exceptionOccurred) { BCLDebug.Trace("REMOTE","Lease ",id," SponsorCall Sponsor Exception "); Unregister(sponsor); ProcessNextSponsor(); } }