public void Fire(List <string> xboxUserIds, CallBufferTimerCompletionContext completionContext = null)
        {
            if (xboxUserIds == null)
            {
                throw new ArgumentNullException("xboxUserIds");
            }

            lock (this.usersToCall)
            {
                this.callBufferTimerCompletionContext = completionContext;
                foreach (string xuid in xboxUserIds)
                {
                    if (!this.usersToCallMap.ContainsKey(xuid))
                    {
                        this.usersToCall.Add(xuid);
                        this.usersToCallMap[xuid] = true;
                    }
                }
            }

            Task.Run(() => { this.FireHelper(); });
        }
        public void Fire(List <XboxLiveUser> users, CallBufferTimerCompletionContext completionContext = null)
        {
            if (users == null)
            {
                throw new ArgumentNullException("users");
            }

            lock (this.usersToCall)
            {
                this.callBufferTimerCompletionContext = completionContext;
                foreach (XboxLiveUser user in users)
                {
                    if (!this.usersToCallMap.ContainsKey(user.XboxUserId))
                    {
                        this.usersToCall.Add(user);
                        this.usersToCallMap[user.XboxUserId] = true;
                    }
                }
            }

            Task.Run(() => { this.FireHelper(); });
        }
        private void FireHelper()
        {
            if (!this.isTaskInProgress)
            {
                TimeSpan timeDiff = (this.duration - (DateTime.Now - this.previousTime));
                if (timeDiff.TotalMilliseconds < 0)
                {
                    timeDiff = TimeSpan.Zero;
                }
                this.isTaskInProgress = true;
                this.previousTime     = DateTime.Now;

                List <string> userCopy;
                lock (this.usersToCall)
                {
                    userCopy = this.usersToCall.ToList();
                }
                var completionContext = this.callBufferTimerCompletionContext;
                Task.Delay(timeDiff).ContinueWith((continuationAction) =>
                {
                    this.isTaskInProgress = false;
                    this.TimerCompleteEvent(this, new CallBufferReturnObject(userCopy, completionContext));
                    if (this.isQueuedTask)
                    {
                        this.isQueuedTask = false;
                        this.FireHelper();
                    }
                });

                this.usersToCall.Clear();
                this.usersToCallMap.Clear();
                this.callBufferTimerCompletionContext = null;
            }
            else
            {
                this.isQueuedTask = true;
            }
        }
 public CallBufferReturnObject(List <string> userList, CallBufferTimerCompletionContext context)
 {
     this.UserList          = userList;
     this.CompletionContext = context;
 }