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."); }
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(); }