private void UpdateBayeuxClientState( BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate) { lock (_stateUpdateInProgressLock) { ++_stateUpdateInProgress; } var oldState = _bayeuxClientState; var newState = create(oldState); if (newState == null) { throw new SystemException(); } if (!oldState.IsUpdateableTo(newState)) { _logger?.LogDebug($"State not updateable : {oldState} -> {newState}"); return; } _bayeuxClientState = newState; postCreate?.Invoke(); if (oldState.Type != newState.Type) { newState.Enter(oldState.Type); } newState.Execute(); // Notify threads waiting in waitFor() lock (_stateUpdateInProgressLock) { --_stateUpdateInProgress; if (_stateUpdateInProgress == 0) { _stateChanged.Set(); } } }
private void UpdateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate) { StateUpdateInProgressMutex.WaitOne(); ++stateUpdateInProgress; StateUpdateInProgressMutex.ReleaseMutex(); BayeuxClientState newState = null; var oldState = bayeuxClientState; newState = create(oldState); if (newState == null) { throw new SystemException(); } if (!oldState.IsUpdateableTo(newState)) { //Console.WriteLine("State not updateable : {0} -> {1}", oldState, newState); return; } bayeuxClientState = newState; postCreate?.Invoke(); if (oldState.Type != newState.Type) { newState.Enter(oldState.Type); } newState.Execute(); // Notify threads waiting in waitFor() StateUpdateInProgressMutex.WaitOne(); --stateUpdateInProgress; if (stateUpdateInProgress == 0) { stateChanged.Set(); } StateUpdateInProgressMutex.ReleaseMutex(); }
private void updateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate) { #if SILVERLIGHT lock (stateUpdateInProgressMutex) { #endif #if !SILVERLIGHT stateUpdateInProgressMutex.WaitOne(); #endif ++stateUpdateInProgress; #if SILVERLIGHT } #endif #if !SILVERLIGHT stateUpdateInProgressMutex.ReleaseMutex(); #endif BayeuxClientState newState = null; BayeuxClientState oldState = bayeuxClientState; newState = create(oldState); if (newState == null) { throw new SystemException(); } if (!oldState.isUpdateableTo(newState)) { //Console.WriteLine("State not updateable : {0} -> {1}", oldState, newState); return; } bayeuxClientState = newState; if (postCreate != null) { postCreate(); } if (oldState.Type != newState.Type) { newState.enter(oldState.Type); } newState.execute(); // Notify threads waiting in waitFor() #if !SILVERLIGHT stateUpdateInProgressMutex.WaitOne(); #endif #if SILVERLIGHT lock (stateUpdateInProgressMutex) { #endif --stateUpdateInProgress; if (stateUpdateInProgress == 0) { stateChanged.Set(); } #if !SILVERLIGHT stateUpdateInProgressMutex.ReleaseMutex(); #endif #if SILVERLIGHT } #endif }
private void updateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate) { stateUpdateInProgressMutex.WaitOne(); ++stateUpdateInProgress; stateUpdateInProgressMutex.ReleaseMutex(); BayeuxClientState newState = null; BayeuxClientState oldState = bayeuxClientState; newState = create(oldState); if (newState == null) throw new SystemException(); if (!oldState.isUpdateableTo(newState)) { //Console.WriteLine("State not updateable : {0} -> {1}", oldState, newState); return; } bayeuxClientState = newState; if (postCreate != null) postCreate(); if (oldState.Type != newState.Type) newState.enter(oldState.Type); newState.execute(); // Notify threads waiting in waitFor() stateUpdateInProgressMutex.WaitOne(); --stateUpdateInProgress; if (stateUpdateInProgress == 0) stateChanged.Set(); stateUpdateInProgressMutex.ReleaseMutex(); }
private void updateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate) { LogHelper.Log($"BayeauxClient: updateBayeuxClientState()..."); stateUpdateInProgressMutex.WaitOne(); ++stateUpdateInProgress; stateUpdateInProgressMutex.ReleaseMutex(); BayeuxClientState newState = null; BayeuxClientState oldState = bayeuxClientState; newState = create(oldState); LogHelper.Log($"BayeauxClient: updateBayeuxClientState() old state: {oldState}, new state: {newState}"); if (newState == null) { throw new SystemException(); } if (!oldState.isUpdateableTo(newState)) { LogHelper.Log($"BayeauxClient: updateBayeuxClientState() State is not updatable from {oldState} to {newState}"); return; } bayeuxClientState = newState; postCreate?.Invoke(); if (oldState.Type != newState.Type) { newState.enter(oldState.Type); } LogHelper.Log($"BayeauxClient: updateBayeuxClientState() executing on {newState}..."); newState.execute(); LogHelper.Log($"BayeauxClient: updateBayeuxClientState() executed on {newState}."); // Notify threads waiting in waitFor() stateUpdateInProgressMutex.WaitOne(); --stateUpdateInProgress; if (stateUpdateInProgress == 0) { stateChanged.Set(); } stateUpdateInProgressMutex.ReleaseMutex(); LogHelper.Log($"BayeauxClient: updateBayeuxClientState() done."); }