public PostgreSqlTaskQueueConsumer(TaskQueueConsumerOptions options, ITimestampProvider timestampProvider)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (timestampProvider == null)
            {
                throw new ArgumentNullException(nameof(timestampProvider));
            }

            mOptions           = options;
            mTimestampProvider = timestampProvider;

            mSignalingConnectionString = options.ConnectionOptions
                                         .ConnectionString
                                         .DeriveSignalingConnectionString(options);

            mNotificationListener = new PostgreSqlTaskQueueNotificationListener(mSignalingConnectionString,
                                                                                options.Mapping.NewTaskNotificationChannelName);

            mNotificationListener.ListenerConnectionRestored +=
                HandleListenerConnectionRestored;
            mNotificationListener.NewTaskPosted +=
                HandleNewTaskUpdateReceived;
            mNotificationListener.ListenerTimedOutWhileWaiting +=
                HandleListenerTimedOut;

            mTaskDequeueSql      = GetTaskDequeueSql(options.Mapping);
            mTaskAcquireSql      = GetTaskAcquireSql(options.Mapping);
            mTaskResultUpdateSql = GetTaskResultUpdateSql(options.Mapping);
        }
        protected void Dispose(bool disposing)
        {
            if (!mIsDisposed)
            {
                if (disposing)
                {
                    ClearForDequeue = null;

                    StopReceivingNewTaskUpdatesAsync()
                    .Wait();

                    mNotificationListener.ListenerConnectionRestored -=
                        HandleListenerConnectionRestored;
                    mNotificationListener.NewTaskPosted -=
                        HandleNewTaskUpdateReceived;
                    mNotificationListener.ListenerTimedOutWhileWaiting -=
                        HandleListenerTimedOut;

                    mNotificationListener.Dispose();
                    mNotificationListener = null;
                }

                mIsDisposed = true;
            }
        }