protected static void PoolableInDoubt(object state)
{
VolatileDemultiplexer demux = (VolatileDemultiplexer)state;
// Don't block an enlistment thread (or a thread pool thread). So
// try to get the transaction lock but if unsuccessfull give up and
// queue this operation to try again later.
bool tookLock = false;
try
{
Monitor.TryEnter(demux._transaction, 250, ref tookLock);
if (tookLock)
{
demux.InternalInDoubt();
}
else
{
if (!ThreadPool.QueueUserWorkItem(InDoubtCallback, demux))
{
throw TransactionException.CreateInvalidOperationException(
TraceSourceType.TraceSourceLtm,
SR.UnexpectedFailureOfThreadPool,
null
);
}
}
}
finally
{
if (tookLock)
{
Monitor.Exit(demux._transaction);
}
}
}