/// <summary>
        /// Task for Receiving messages from Jetstream Ground.
        /// </summary>
        private string ReceiveTask(CancellationToken ct)
        {
            try
            {
                JetstreamServiceClient client   = new JetstreamServiceClient(this.JetstreamUrl, this.UserAccessKey);
                GetEventsRequest       request  = new GetEventsRequest();
                GetEventsResponse      response = client.GetEvents(request);
                string currentBatchId           = response.BatchId;
                List <TersoSolutions.Jetstream.SDK.Application.Messages.JetstreamEvent> messages = new List <TersoSolutions.Jetstream.SDK.Application.Messages.JetstreamEvent>();
                foreach (TersoSolutions.Jetstream.SDK.Application.Messages.JetstreamEvent message in response.Events)
                {
                    messages.Add(message);
                }

                // now add the Messages to the data store for the window thread
                if (!ct.IsCancellationRequested)
                {
                    lock (_setLock)
                    {
                        for (int i = 0; i < messages.Count; i++)
                        {
                            if (ct.IsCancellationRequested)
                            {
                                break;
                            }
                            _set.Add(messages[i]);
                        }
                    }
                }
                return(currentBatchId);
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("JetstreamSDK",
                                    ex.Message + "\n" + ex.StackTrace,
                                    EventLogEntryType.Error);
            }
            return(string.Empty);
        }
        /// <summary>
        /// Task for Receiving messages from Jetstream Ground.
        /// </summary>
        private string ReceiveTask(CancellationToken ct)
        {
            try
            {
                JetstreamServiceClient client = new JetstreamServiceClient(JetstreamUrl, UserAccessKey);
                GetEventsRequest request = new GetEventsRequest();
                GetEventsResponse response = client.GetEvents(request);
                string currentBatchId = response.BatchId;
                List<JetstreamEvent> messages = response.Events.ToList();

                // now add the Messages to the data store for the window thread
                if (ct.IsCancellationRequested)
                {
                    return currentBatchId;
                }

                lock (_setLock)
                {
                    foreach (JetstreamEvent t in messages)
                    {
                        if (ct.IsCancellationRequested)
                        {
                            break;
                        }
                        _set.Add(t);
                    }
                }
                return currentBatchId;
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry(EventLogSource, ex.Message + "\n" + ex.StackTrace, EventLogEntryType.Error);
            }
            return String.Empty;
        }
        public void GetEventsTest()
        {

            // construct a Jetstream service client
            JetstreamServiceClient client = new JetstreamServiceClient(JetstreamConfiguration.Url, JetstreamConfiguration.ApplicationAccessKey);

            try
            {
                // create and configure the request object
                GetEventsRequest request = new GetEventsRequest();
                request.Limit = 2;
                // call the Jetstream ReST endpoint 
                client.GetEvents(request);
            }
            catch (Exception ex)
            {
               Assert.Fail(ex.ToString());
            }
        }