public void DeliverComplete()
{
Worker w, z;
lock (this)
{
w = completeList_;
z = w;
completeList_ = null;
completeListEnd_ = null;
}
if (z != null)
{
while (w != null)
{
try
{
if (w.completion_ != null)
w.completion_(w, w.error_);
}
catch (System.Exception x)
{
Console.WriteLine("Exception thrown within worker completion! {0}", x.Message);
// retain the un-delivered notifications; leak the worker records already delivered
if (completeList_ == null)
completeList_ = w.next_;
else
completeListEnd_.next_ = w.next_;
completeListEnd_ = w.next_;
throw new Exception("The thread pool user threw an exception on delivery.", x);
}
w = w.next_;
}
lock (this)
{
// I could link in the entire chain in one swoop if I kept some
// more state around, but this seems simpler.
while (z != null)
{
w = z.next_;
z.next_ = freeList_;
freeList_ = z;
z = w;
}
}
}
}