void DoWorkInternal()

in src/SerializedWorker.cs [125:185]


        void DoWorkInternal(T work, bool fromList)
        {
            while (work != null)
            {
                if (this.workDelegate.Invoke(work))
                {
                    lock (this.SyncRoot)
                    {
                        work = null;
                        if (this.state != State.Aborted)
                        {
                            if (fromList && this.pendingWorkList.First != null)
                            {
                                this.pendingWorkList.RemoveFirst();
                            }

                            if (this.pendingWorkList.First != null)
                            {
                                work = this.pendingWorkList.First.Value;
                                fromList = true;
                            }

                            if (work == null)
                            {
                                // either there is no work or the worker was aborted
                                this.state = State.Idle;
                                return;
                            }

                            this.state = State.Busy;
                        }
                    }
                }
                else
                {
                    lock (this.SyncRoot)
                    {
                        if (this.state == State.Aborted)
                        {
                            work = null;
                        }
                        else if (this.state == State.BusyWithContinue)
                        {
                            // Continue called right after workFunc returned false
                            this.state = State.Busy;
                        }
                        else
                        {
                            if (!fromList)
                            {
                                // add to the head since later work may be queued already
                                this.pendingWorkList.AddFirst(work);
                            }

                            this.state = State.WaitingForContinue;
                            work = null;
                        }
                    }
                }
            }
        }