.NET1.1的版本.
// ?2005 IDesign Inc. All rights reserved
//Questions? Comments? go to
//
http://www.idesign.net
using System;
using System.EnterpriseServices;
public enum TransactionScopeOption
{
Suppress = TransactionOption.NotSupported,
Required = TransactionOption.Required,
RequiresNew = TransactionOption.RequiresNew
}
public class TransactionScope : IDisposable
{
bool m_Consistent = false;
public void Complete()
{
if(m_Consistent == false)
{
m_Consistent = true;
}
else
{
throw new InvalidOperationException("Cannot call Complete() more than once");
}
}
public TransactionScope() : this(TransactionScopeOption.Required)
{}
public TransactionScope(TransactionScopeOption scopeOption)
{
ServiceConfig config = new ServiceConfig();
config.Transaction = (TransactionOption)scopeOption;
ServiceDomain.Enter(config);
}
public void Dispose()
{
if(m_Consistent == false && ContextUtil.IsInTransaction)
{
ContextUtil.MyTransactionVote = TransactionVote.Abort;
}
ServiceDomain.Leave();
m_Consistent = false;
}
}