// This method never throws - possible exception already handled inside.
        private bool GenerateMessageSafe()
        {
            bool quitLifeCycle = false;

            try
            {
                State = WorkerState.Busy;
                bool completed = GenerateMessageNetTimed();
                WorkerStatistics.Send();
                if (completed)
                {
                    Tracer.Info("First worker {0} reports completion!", WorkerId);
                    State         = WorkerState.Completed;
                    quitLifeCycle = true;
                }
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
                ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.WorkerStep, ex);
                problemReport.SendProblemReport(ReportPipe);
                quitLifeCycle = true; // Worker which caused unhandled exception should quit rather than try to process more messages
            }
            return(quitLifeCycle);
        }
 /// <summary>
 /// Sets the total document count.
 /// </summary>
 /// <param name="totalDocumentCount">The total document count.</param>
 private void SetTotalDocumentCount(int totalDocumentCount)
 {
     if (WorkerStatistics == null)
     {
         return;
     }
     WorkerStatistics.PunchInNet();
     WorkerStatistics.SetTotalDocumentCount(totalDocumentCount);
     WorkerStatistics.PunchOutNet();
     WorkerStatistics.Send();
 }
        // This method never throws - possible exception already handled inside.
        private bool ProcessMessageSafe()
        {
            bool quitLifeCycle = false;

            try
            {
#if RECEIVE_WAITS
                PipeMessageEnvelope message = InputDataPipe.Receive(InputDataPipeReceiveTimeout);
#else
                PipeMessageEnvelope message = InputDataPipe.Receive(_zeroWait);
#endif
                if (null != message)
                {
                    State = WorkerState.Busy;
                    SlowDownPostbacks(message);
                    ProcessMessageNoTrans(message);
                }
                else
                {
                    State = WorkerState.Idle;
#if RECEIVE_WAITS
                    WorkerStatistics.RecordIdleTime(InputDataPipeReceiveTimeout);
#else
                    Thread.Sleep(InputDataPipeReceiveTimeout);
#endif
                }
                WorkerStatistics.Send();
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
                ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.WorkerStep, ex);
                problemReport.SendProblemReport(ReportPipe);
                quitLifeCycle = true; // Worker which caused unhandled exception should quit rather than try to process more messages
            }
            return(quitLifeCycle);
        }