Transaction Class API

Transaction class constructors are described in the following table:

Constructor

Description/Notes

protected Transaction(ServiceBase srvc);

Accepts service as an argument.

protected Transaction(ServiceBase srvc, TimeSpan timeout)

Accepts service as an argument, and limits the transaction time to the provided timeout.

If the timeout is too short, and it fires before the Result can set it and get to fetch a return value, it is possible to get the following exception: InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.

Transaction class properties are described in the following table:

Property

Description/Notes

public ServiceBase Service;

Property to get service.

public T Result;

Call to this property wait until a result is returned by the SetResult or SetException methods. This property throws a System.AggregateException exception set by the SetException method.

tog_minusTransaction Class Methods

Transaction class methods are described in the following table:

Method

Description/Notes

public void SetResult(T obj);

Sets the result to be returned in the Result property. The method is type safe, and result compatibility is checked in compile time

public void SetException(Exception ex);

Throws the exception from the Result property.

static public void ParallelStart(params IParallelTransaction[] obj);

Starts a number of transactions at the same time. The function waits for all transactions to be completed before it returns. In order to be able to use this method, a transaction must be derived from the IParallelTransaction interface.

protected abstract void Cleanup();

Location for clean up code. The function is called when a transaction is about to be disposed.

For an example of creating and implementing a transaction class, refer to Writing Transactions.