NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Voting in an Automatic Transaction

NGWS classes and ASP+ pages can vote to commit or abort their current transaction. The absence of an explicit vote in your code casts a commit vote by default. The default commit, however, may decrease the performance of your application by lengthening the time it takes for each transaction to release expensive resources.

Explicit voting also allows your class or page to abort a transaction if it encounters a significant error. Again, you can improve your application's performance by catching a fatal error early in the transaction, ending the transaction, and releasing resources.

You can use Microsoft.ComServices.ContextUtil, which exposes the SetComplete or SetAbort members, to explicitly commit or abort a transaction. SetComplete indicates that your object votes to commit its work; SetAbort indicates that your object encountered a problem and votes to abort the ongoing transaction.

The following code fragment shows the SetAbort method in use.

// try to do something crucial to transaction completing
if( !DoSomeWork() ) 
{
  ContextUtil.SetAbort();
}