Amnesia.SessionTracker.DecrementActivityCount C# (CSharp) Method

DecrementActivityCount() private method

Called when an activity is completed. Both async and sync activities.
private DecrementActivityCount ( ) : void
return void
        private void DecrementActivityCount()
        {
            // ASSERT: one activity is executing
            if (activityCount == 0)
                throw new InvalidOperationException("Unbalanced call to EndActivity");

            // ASSERT: at least one thread is bound to the current activity
            var activity = CurrentThreadActivity;
            if (activity == null)
                throw new InvalidOperationException("Unbalanced call to EndActivity");

            CurrentThreadActivity = null;

            if (activity.ThreadCount == 0)
                throw new InvalidOperationException("Unbalanced call to EndActivity");

            // Have all threads completed work on this activity?
            --activity.ThreadCount;

            if (activity.ThreadCount == 0)
            {
                // activity is complete
                --activityCount;

                // Notify any interested thread that there are no more activities executing
                if (activitiesDone != null)
                {
                    --pendingActivities;

                    if(pendingActivities == 0)
                        activitiesDone.Set();
                }
            }
        }