コード例 #1
0
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("StoreWorker entry point called", "Information");
            string lastWriteStore = null;

            while (!_stopping)
            {
                try
                {
                    var jobInfo = _jobQueue.NextJob(lastWriteStore);
                    if (jobInfo == null)
                    {
                        if (lastWriteStore == null)
                        {
                            Thread.Sleep(IdleSleepPeriod);
                        }
                        else
                        {
                            lastWriteStore = null;
                        }
                    }
                    else
                    {
                        try
                        {
                            lastWriteStore = jobInfo.StoreId;
                            ProcessJob(jobInfo);
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceError("Error processing job {0}. Cause: {1}.", jobInfo.Id, ex);
                            _jobQueue.FailWithException(jobInfo.Id,
                                                        "Unexpected internal exception during job processing. ", ex);
                            lastWriteStore = null;
                        }
                        Thread.Sleep(BusySleepPeriod);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Error in run loop: {0}", ex);
                }
            }
        }