Object Pooling/Just In Time Activation Sample | (Windows Forms Application) |
This document contains the release information for the .NET Framework Object Pooling/Just In Time Activation sample. You will find the following sections below:
This sample demonstrates the use of Just In Time Activation and Object Pooling in a .NET environment. A simple pooled object writes strings out to a log file. Several client apps instantiate and call into the pooled object class. With Just-In-Time Activation enabled and a maximum pool size of one object, all client calls are routed through a single object instance. The result is a single log file that documents COM+ activity to manage the pool and also shows multiple clients calling into pooled object. An object construction string is used to specify the log file name and (potentially) fully qualified path.
Just In Time Activation is a COM+ service that permits clients to create and hold on to an object reference for indefinite lengths of time without requiring that an actual object instance exist behind it. COM+ will activate an object just in time for a consumer when it calls through its object reference. This activation might consist of creating a new object instance or, when used in combination with COM+ Object Pooling, passing the caller a reference to a pooled object. COM+ deactivates an object based on the doneness bit on the object context. For .NET ServicedComponents, the AutoComplete attribute can be applied to class methods, indicating that the object can be deactivated on exit from the method.
COM+ Object Pooling is a service that will maintain a pool of active objects, ready to be used by a client that requests a component configured for pooling. The pool can be configured administratively and by means of the ObjectPooling attribute. Pool attributes include a minimum and maximum size of the pool and an object creation request timeout value.
JITA- and Object Pooling-enabled components can control how they are reused by implementing the IObjectControl interface. IObjectControl methods are called by COM+ (and COM+ only) in order to indicate key events in the object activation/deactivation process or to ask the object whether it can be returned to the object pool. This sample implements IObjectControl in order to demonstrate the interface being used by COM+ but does nothing meaningful in its implementation.
See the Platform SDK documentation for important advantages and considerations for using both Just In Time Activation and Object Pooling.
The following bullets briefly describe the technologies used by this sample.
This sample is located in the Technologies\ComponentServices\ObjectPooling subdirectory of the .NET Framework SDK samples directory.
For Example:
C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\ObjectPooling
In order to properly build and run this sample, the following steps need to be performed.
Type BuildAll.bat from the command line.
For Example:
C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\ObjectPooling>buildall.bat
If you're building the sample from Visual Studio 7, you will need to install the OPDemoSvr.dll assembly to the Global Assembly Cache before running the sample. Note: The gacutil.exe program is located in the SDK\v1.1\Bin directory.
For Example:
C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\ObjectPooling\CS>gacutil -i OPDemoSvr.dll
The sample builds a C# and VB version of the client application and COM+ component. Source code for each language is stored in subdirectories named \CS and \VB. The C# component has 'CS' appended to its name as viewed in the Component Services administrative tool, 'OPDemoServerCS.PooledLogFile'. The VB version is named 'OPDemoServerVB.PooledLogFile'. When working with the sample code, be sure to observe and/or modify the version of the COM+ component that corresponds to the client application you launch.
Review comments in the source code and build.bat files for more information on sample binary creation and registration steps.
In order to run this sample, follow the instructions listed below.
For Example:
C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\ObjectPooling\CS>start opdemo.exe
In order to uninstall this sample, follow the instructions listed below.
For the .Net Framework samples to function properly, your Path, Include, and Lib environment variables must be set correctly. In many cases, the SDK install program updates these environment variables for you. However, if you installed the .Net Framework SDK using Visual Studio .NET, or unselected "register environment variables" during setup, these environment variables will not be updated. You can set the Path, Include and Lib environment variables by running SDKVars.bat, located in the <SDKRoot>\Bin directory. SDKVars.bat must be executed in every command shell.