private void SendTrackedUsersChanged(EventQueueSection section)
 {
     section.Enqueue(
         () =>
         {
             if (this.TrackedUsersChanged != null)
             {
                 this.TrackedUsersChanged(this, EventArgs.Empty);
             }
         });
 }
        private void SetEngagedUserTrackingId(int newId, EventQueueSection section)
        {
            int oldId = this.EngagedUserTrackingId;
            this.EngagedUserTrackingId = newId;

            if (oldId != newId)
            {
                section.Enqueue(
                    () =>
                    {
                        if (this.EngagedUserChanged != null)
                        {
                            var args = new UserTrackingIdChangedEventArgs(oldId, newId);
                            this.EngagedUserChanged(this, args);
                        }
                    });
            }
        }
        internal void SetPrimaryUserTrackingId(int newId, EventQueueSection section)
        {
            int oldId = this.PrimaryUserTrackingId;
            this.PrimaryUserTrackingId = newId;

            if (oldId != newId)
            {
                section.Enqueue(
                    () =>
                    {
                        if (this.PrimaryUserChanged != null)
                        {
                            var args = new UserTrackingIdChangedEventArgs(oldId, newId);
                            this.PrimaryUserChanged(this, args);
                        }
                    });

                // If the new primary user is the same as the engaged user, then there is no candidate user.
                // Otherwise, we have a new candidate user as long as the new primary user is a valid user.
                this.SetCandidateUserTrackingId(
                    (this.EngagedUserTrackingId != InvalidUserTrackingId) && (this.EngagedUserTrackingId == newId)
                        ? InvalidUserTrackingId
                        : newId,
                    section);
            }
        }