// Token: 0x060003F4 RID: 1012 RVA: 0x00013598 File Offset: 0x00011798
 protected TimeBasedDatabaseJob GetPendingJob(bool cycleDemandJob = true)
 {
     if (this.demandJobs.Count > 0)
     {
         TimeBasedDatabaseDemandJob timeBasedDatabaseDemandJob = this.demandJobs[0];
         if (cycleDemandJob)
         {
             this.demandJobs.RemoveAt(0);
             this.demandJobs.Add(timeBasedDatabaseDemandJob);
         }
         return(timeBasedDatabaseDemandJob);
     }
     return(this.windowJob);
 }
        // Token: 0x060003F3 RID: 1011 RVA: 0x00013198 File Offset: 0x00011398
        protected AssistantTaskContext ProcessOneMailbox(ref AssistantTaskContext context)
        {
            lock (this.instanceLock)
            {
                if (context == null)
                {
                    if (!this.started)
                    {
                        ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug <TimeBasedDatabaseDriver, string>((long)this.GetHashCode(), "{0}: Worker bailing (Not started) for assistant: {1}", this, this.Assistant.NonLocalizedName);
                        AssistantsLog.LogNotStartedEvent(this.Assistant.NonLocalizedName, this.Assistant as AssistantBase);
                        return(null);
                    }
                    if (this.TotalMailboxesQueued == 0U)
                    {
                        ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug <TimeBasedDatabaseDriver, string>((long)this.GetHashCode(), "{0}: Worker bailing (Empty queue) for assistant: {1}", this, this.Assistant.NonLocalizedName);
                        AssistantsLog.LogNoMailboxesPendingEvent(this.Assistant.NonLocalizedName);
                        return(null);
                    }
                }
                if (this.workersActive++ == 0)
                {
                    FastManualResetEvent fastManualResetEvent = this.workerThreadsClear;
                    if (fastManualResetEvent != null)
                    {
                        fastManualResetEvent.Reset();
                    }
                }
                ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug <TimeBasedDatabaseDriver, int, string>((long)this.GetHashCode(), "{0}: Worker started. Workers Active on this Driver: {1}, assistant: {2}", this, this.workersActive, this.Assistant.NonLocalizedName);
            }
            AssistantTaskContext assistantTaskContext = null;
            TimeBasedDatabaseJob timeBasedDatabaseJob = null;
            MailboxData          mailboxData          = null;

            try
            {
                if (context == null)
                {
                    lock (this.instanceLock)
                    {
                        timeBasedDatabaseJob = this.GetPendingJob(true);
                        ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug <TimeBasedDatabaseDriver, uint, string>((long)this.GetHashCode(), "{0}: Total Mailboxes Queued on this database: {1}, assistant: {2}", this, this.TotalMailboxesQueued, this.Assistant.NonLocalizedName);
                    }
                    if (timeBasedDatabaseJob != null)
                    {
                        mailboxData = timeBasedDatabaseJob.GetNextMailbox();
                        if (mailboxData != null)
                        {
                            context = this.Assistant.InitializeContext(mailboxData, timeBasedDatabaseJob);
                        }
                    }
                    else
                    {
                        AssistantsLog.LogNoJobsEvent(this.Assistant.NonLocalizedName);
                    }
                }
                else
                {
                    timeBasedDatabaseJob = context.Job;
                    mailboxData          = context.MailboxData;
                }
                if (context != null && context.Job != null)
                {
                    assistantTaskContext = context.Job.ProcessNextMailbox(context);
                }
            }
            catch
            {
                lock (this.instanceLock)
                {
                    if (--this.workersActive == 0)
                    {
                        ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug <TimeBasedDatabaseDriver, int, string>((long)this.GetHashCode(), "{0}: Worker exiting due to exception. Workers Active {1}, assistant: {2}", this, this.workersActive, this.Assistant.NonLocalizedName);
                        this.workerThreadsClear.Set();
                    }
                }
                throw;
            }
            finally
            {
                if (timeBasedDatabaseJob != null && mailboxData != null && (assistantTaskContext == null || context == null))
                {
                    timeBasedDatabaseJob.RemoveFromActive(mailboxData);
                    timeBasedDatabaseJob.FinishIfNecessary();
                }
            }
            lock (this.instanceLock)
            {
                try
                {
                    ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug <TimeBasedDatabaseDriver, int, uint>((long)this.GetHashCode(), "{0}: Yielding thread. Workers Active: {1}, Remaining Mailboxes on this database: {2}", this, this.workersActive, this.TotalMailboxesQueued);
                    if (context != null && context.Job != null && (context.Job.MailboxesQueued == 0 || context.Job.Finished))
                    {
                        TimeBasedDatabaseDemandJob timeBasedDatabaseDemandJob = context.Job as TimeBasedDatabaseDemandJob;
                        if (timeBasedDatabaseDemandJob != null)
                        {
                            this.demandJobs.Remove(timeBasedDatabaseDemandJob);
                            ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug <TimeBasedDatabaseDriver, int>((long)this.GetHashCode(), "{0}: Demand Job is done and has been removed. Remaining Demand Jobs: {1}", this, this.demandJobs.Count);
                        }
                        else
                        {
                            this.RemoveWindowJobWithHistoryEntry();
                        }
                    }
                }
                finally
                {
                    if (--this.workersActive == 0)
                    {
                        ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug <TimeBasedDatabaseDriver, int>((long)this.GetHashCode(), "{0}: Worker exiting. Workers Active {1}", this, this.workersActive);
                        this.workerThreadsClear.Set();
                    }
                }
            }
            return(assistantTaskContext);
        }