Adding a New Method to the MoveMoney Component

To implement the scenario for this section, you will add a method similar to Perform, named StatefulPerform, which uses class member variables to set account numbers. Thus, MoveMoney becomes a stateful object when StatefulPerform is called.

To add a new function to the MoveMoney component
  1. Open the \MTx\Samples\Account.VB\Step6\Account.vbp project.

Click here to see the StatefulPerform method

  1. Build the component as a dynamic-link library (DLL) and save it as \MTx\Samples\Account.VB\Step6\VBAcct.dll.

The code for StatefulPerform calls the Perform method. The methods differ in how the account numbers are set. Class member variables for each account must be set before calling StatefulPerform, whereas Perform passes the account numbers by value through function parameters.

When you click the MoveMoney option in the Sample Bank client, it calls the following code to initialize the function:

lRet = obj.Perform(CLng(PrimeAcct), lSecondAcct, CLng(Amount), TranType, Res)

When you click the Stateful MoveMoney option, the Sample Bank client calls the following code to initialize the function:

obj.PrimeAccountNo = PrimeAcct
obj.SecondAccountNo = lSecondAcct
lRet = obj.StatefulPerform(CLng(Amount), TranType, Res)

The PrimeAccountNo and SecondAccountNo properties are actually separate class member variables on the MoveMoney object. Note that the PrimeAccountNo and SecondAccountNo properties aren't accessed through the Shared Property Manager properties; the MoveMoney object controls getting and setting the account number values, thus making the MoveMoney object stateful.

Run the Bank client with the MoveMoney option. Then run it again with the Stateful MoveMoney option. You should notice that the stateless version is slightly faster. Try running multiple Bank clients with concurrent transactions. You should notice that the stateless version performs significantly better. The next section explains why.

See Also

Transactions, Deactivating Objects, Context Objects, Stateful Components