COM+ Transaction scope in .Net
-
I've just started to work on a windows service with distributed transactions using com+ and have stumbled upon a design question: When is a transaction started? Is it when the class is created or when a method is invoked. Consider the example below:
[Transaction(TransactionOption.Required)]
public class TransactionTest : ServicedComponent
{
public TransactionTest()
{} public void BeginLoop(int count) { for (int i = 0; i < count; ++i) MakeTransactions(); } \[AutoComplete\] private void MakeTransactions() { //Make some transactions if ((new Random()).Next(10) < 4) ContextUtil.SetAbort(); else ContextUtil.SetComplete(); } }
A simple transaction based class with a method that is being invoked multiple times internally. Are all calls to MakeTransactions() in the same transaction or is a new transaction started each time SetAbort/Complete is invoked?
-
I've just started to work on a windows service with distributed transactions using com+ and have stumbled upon a design question: When is a transaction started? Is it when the class is created or when a method is invoked. Consider the example below:
[Transaction(TransactionOption.Required)]
public class TransactionTest : ServicedComponent
{
public TransactionTest()
{} public void BeginLoop(int count) { for (int i = 0; i < count; ++i) MakeTransactions(); } \[AutoComplete\] private void MakeTransactions() { //Make some transactions if ((new Random()).Next(10) < 4) ContextUtil.SetAbort(); else ContextUtil.SetComplete(); } }
A simple transaction based class with a method that is being invoked multiple times internally. Are all calls to MakeTransactions() in the same transaction or is a new transaction started each time SetAbort/Complete is invoked?
Short answer is I don't know. I know there is a difference between starting a transaction and participating in one. The code you posted could result in only a single transaction being started and multiple participations in the transaction. There are many resources available on MSDN for the Transaction topic that you may want to dig into.
led mike
-
I've just started to work on a windows service with distributed transactions using com+ and have stumbled upon a design question: When is a transaction started? Is it when the class is created or when a method is invoked. Consider the example below:
[Transaction(TransactionOption.Required)]
public class TransactionTest : ServicedComponent
{
public TransactionTest()
{} public void BeginLoop(int count) { for (int i = 0; i < count; ++i) MakeTransactions(); } \[AutoComplete\] private void MakeTransactions() { //Make some transactions if ((new Random()).Next(10) < 4) ContextUtil.SetAbort(); else ContextUtil.SetComplete(); } }
A simple transaction based class with a method that is being invoked multiple times internally. Are all calls to MakeTransactions() in the same transaction or is a new transaction started each time SetAbort/Complete is invoked?
I can only point you to Tim Ewald's excellent book Transactional COM+[^]. Note that this only covers COM+ up to Windows 2000, and the little information it has on .NET is out of date (it was published in 2001), but the core information is very much correct.
DoEvents: Generating unexpected recursion since 1991