public void QueueMessage(ContentInfo contentInfo, bool isNew, Context c)
        {
            context = c;
            if (isNew)
            {
                ThreadPool.QueueUserWorkItem(delegate
                {
                    dbm.InsertOrUpdateContentInfoItems(new List<ContentInfo>() { contentInfo });
                });
            }//end if

            this.ContentInfoQ.Enqueue(contentInfo);

            if (!this.IsSendingMessage)
            {

                this.IsSendingMessage = true;

                ContentInfo toSend = this.ContentInfoQ.Dequeue();
                toSend.Message.MessageSent = DateTime.Now;

                try
                {
                    LOLMessageClient service = new LOLMessageClient(LOLConstants.DefaultHttpBinding, LOLConstants.LOLMessageEndpoint);
                    service.MessageCreateCompleted += Service_MessageCreateCompleted;
                    service.MessageCreateAsync(contentInfo.Message,
                                           contentInfo.Message.MessageSteps,
                                           contentInfo.Recipients, AndroidData.CurrentUser.AccountID,
                                           new Guid(AndroidData.ServiceAuthToken), toSend);
                } catch (Exception e)
                {
                    #if DEBUG
                    System.Diagnostics.Debug.WriteLine("Exception thrown - {0}--{1}", e.Message, e.StackTrace);
                    #endif
                }

            }//end if else
        }
        private void SendNextMessage(LOLMessageClient service)
        {
            if (!AndroidData.IsAppActive)
            {
                List<ContentInfo> cacheList = new List<ContentInfo>();
                int qCount = this.ContentInfoQ.Count;
                for (int i = 0; i < qCount; i++)
                    cacheList.Add(this.ContentInfoQ.Dequeue());

                dbm.InsertOrUpdateContentInfoItems(cacheList);
                this.IsSendingMessage = false;
                return;
            }

            if (!this.IsSendingMessage)
            {

                if (this.ContentInfoQ.Count > 0)
                {

                    ContentInfo toSend = this.ContentInfoQ.Dequeue();
                    toSend.Message.MessageSent = DateTime.Now;
                    #if DEBUG
                    //RunOnUiThread (() =>System.Diagnostics.Debug.WriteLine ("just do something here"));
                    #endif
                    this.IsSendingMessage = true;

                    if (!toSend.IsFailed && toSend.Retries++ < this.maxRetries)
                    {
                        service.MessageCreateCompleted += Service_MessageCreateCompleted;
                        service.MessageCreateAsync(toSend.Message, toSend.Message.MessageSteps, toSend.Recipients, AndroidData.CurrentUser.AccountID,
                                                    new Guid(AndroidData.ServiceAuthToken), toSend);
                    } else
                    {
                        if (toSend.Retries++ >= this.maxRetries)
                        {
                            // If the max number of retries has been reached, cache the message content and proceed.
            #if(DEBUG)
                            System.Diagnostics.Debug.WriteLine("Max retries: {0}. Will cache message for later.", toSend.Retries);
            #endif
                            dbm.InsertOrUpdateContentInfoItems(new List<ContentInfo>() { toSend });
                            this.IsSendingMessage = false;
                            this.SendNextMessage(service);
                        } else
                        {
                            this.SendNextStep(toSend, service);
                        }//end if else
                    }//end if else
                } else
                {
            #if(DEBUG)
                    System.Diagnostics.Debug.WriteLine("Finished sending messages!");
            #endif
                }//end if else
            }//end if
        }