/// <summary>
        /// Starts this instance.
        /// </summary>
        public void Start()
        {
            if (this._useLocalPayloadStore && this._storeRepository == null)
            {
                Debug.WriteLine(this.GetType().Name + ": Initializing StoreContext from: " + nameof(this.Start) + "...");
                this._storeRepository = PayloadStoreRepositoryHelper.CreatePayloadStoreRepository();
                this._storeRepository.MakeSureDatabaseExistsAndReady();
                Debug.WriteLine(this.GetType().Name + ": Initialized StoreContext from: " + nameof(this.Start) + ".");
            }

            if (this._rollbarCommThread == null)
            {
#if NETFX
                HostingEnvironment.RegisterObject(this);
#endif
                this._rollbarCommThread = new Thread(new ParameterizedThreadStart(this.KeepProcessingAllQueues))
                {
                    IsBackground = true,
                    Name         = "RollbarProcessor",
                    //Priority = ThreadPriority.AboveNormal,
                };

                this._cancellationTokenSource = new CancellationTokenSource();
                this._rollbarCommThread.Start(_cancellationTokenSource.Token);
            }
        }
        private void ReevaluateUseOfLocalPayloadStore()
        {
            foreach (var queue in _allQueues)
            {
                if (queue.Logger.Config.EnableLocalPayloadStore)
                {
                    this._useLocalPayloadStore = true;
                    if (this._storeRepository == null)
                    {
                        Debug.WriteLine(this.GetType().Name + ": Initializing StoreContext from: " + nameof(this.ReevaluateUseOfLocalPayloadStore) + "...");
                        this._storeRepository = PayloadStoreRepositoryHelper.CreatePayloadStoreRepository();
                        this._storeRepository.MakeSureDatabaseExistsAndReady();
                        Debug.WriteLine(this.GetType().Name + ": Initialized StoreContext from: " + nameof(this.ReevaluateUseOfLocalPayloadStore) + ".");
                    }
                    return;
                }
            }

            this._useLocalPayloadStore = false;
        }
        /// <summary>
        /// Completes the processing.
        /// </summary>
        private void CompleteProcessing()
        {
            Debug.WriteLine("Entering " + this.GetType().FullName + "." + nameof(this.CompleteProcessing) + "() method...");
#if NETFX
            HostingEnvironment.UnregisterObject(this);
#endif
            if (this._cancellationTokenSource != null)
            {
                this._cancellationTokenSource.Dispose();
                this._cancellationTokenSource = null;
                this._rollbarCommThread       = null;
            }

            if (this._storeRepository != null)
            {
                //this._storeRepository.SaveChanges(); // I did not see any change of the context that was not saved immediatly
                this._storeRepository.Dispose();
                this._storeRepository = null;
            }
        }
        /// <summary>
        /// Registers the specified queue.
        /// </summary>
        /// <param name="queue">The queue.</param>
        internal void Register(PayloadQueue queue)
        {
            lock (this._syncLock)
            {
                Assumption.AssertTrue(!this._allQueues.Contains(queue), nameof(queue));

                this._allQueues.Add(queue);
                this.IndexByToken(queue);

                this._useLocalPayloadStore |= queue.Logger.Config.EnableLocalPayloadStore;
                if (this._useLocalPayloadStore && this._storeRepository == null)
                {
                    Debug.WriteLine(this.GetType().Name + ": Initializing StoreContext from: " + nameof(this.Register) + "...");
                    this._storeRepository = PayloadStoreRepositoryHelper.CreatePayloadStoreRepository();
                    this._storeRepository.MakeSureDatabaseExistsAndReady();
                    Debug.WriteLine(this.GetType().Name + ": Initialized StoreContext from: " + nameof(this.Register) + ".");
                }

                ((RollbarConfig)queue.Logger.Config).Reconfigured += Config_Reconfigured;

                // The following debug line causes stack overflow when RollbarTraceListener is activated:
                Debug.WriteLineIf(RollbarTraceListener.InstanceCount == 0, this.GetType().Name + ": Registered a queue. Total queues count: " + this._allQueues.Count + ".");
            }
        }