public static Boolean PerformPassivation(ref Int32 transitionState, ref InProgressTracker passivationInProgress, InProgressTracker activationInProgress, Int32 waitTime, Action passivationAction) { Int32 initialState = (Int32)(new InProgressTracker().Equals(activationInProgress) ? ActivationState.DURING_ACTIVATION : ActivationState.ACTIVE); Int32 prevState; Boolean actionInvoked; Boolean tryAgain; #if SILVERLIGHT using (var waitEvt = new ManualResetEvent(false)) #else using (var waitEvt = new ManualResetEventSlim(false)) #endif { do { prevState = ApplicationSkeleton.ThreadsafeStateTransition(ref transitionState, initialState, (Int32)ActivationState.DURING_PASSIVATION, (Int32)ActivationState.PASSIVE, false, ref passivationInProgress, waitTime, passivationAction); actionInvoked = prevState == initialState; tryAgain = !actionInvoked && prevState != (Int32)ActivationState.PASSIVE && prevState != (Int32)ActivationState.DURING_PASSIVATION; if (tryAgain && initialState == (Int32)ActivationState.ACTIVE) { // Wait if we are not inside activation action, // and if transition state change failed because activation is in progress. #if SILVERLIGHT waitEvt.WaitOne(waitTime); #else waitEvt.Wait(waitTime); #endif } } while (tryAgain); } return(actionInvoked); }
public void DisablePrototype(Int32 compositeMethodIndex, MethodGenericArgumentsInfo gArgsInfo, AbstractFragmentMethodModel nextMethod) { ApplicationSkeleton.ThreadsafeStateTransition(ref this._isPrototype, (Int32)PrototypeState.PROTOTYPE, (Int32)PrototypeState.IN_TRANSITION_RUNNING_ACTION, (Int32)PrototypeState.NOT_PROTOTYPE, true, ref this._isPrototypeTransitionInProgress, ApplicationSkeleton.WAIT_TIME, () => { this.RunPrototypeAction(compositeMethodIndex, gArgsInfo, nextMethod); Interlocked.Exchange(ref this._isPrototype, (Int32)PrototypeState.IN_TRANSITION_CHECKING_STATE); this.CheckCompositeState(compositeMethodIndex, gArgsInfo, nextMethod); ((CompositeModelImmutable)this.ModelInfo.Model).InvokeCompositeInstantiated(this); }); }