System.Transactions.VolatileDemultiplexer.PoolableInDoubt C# (CSharp) Method

PoolableInDoubt() protected static method

protected static PoolableInDoubt ( object state ) : void
state object
return void
        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);
                }
            }
        }

Usage Example

 public override void InDoubt(IPromotedEnlistment en)
 {
     base.oletxEnlistment = en;
     VolatileDemultiplexer.PoolableInDoubt(this);
 }