|
|
|
VB6 objects can't be pooled under COM+, because they are apartment threaded. This restriction is void with VB.NET objects (and all .NET objects in general), because they are free-threaded. To make an object poolable you just need to decorate the class with the ObjectPooling attribute: |
The attribute's constructor is overloaded to let you initialize the Enabled, MaxPoolSize, and MinPoolSize properties: ' enable object pooling, with MaxPoolSize set to 100, and MinPoolSize set to 10
The default value for MinPoolSize is 0, the default value for MaxPoolSize is 1,048,576. You can also set the CreationTimeout property, whose default value is 60 milliseconds, which indicates the time to wait for an object to become available in the pool before throwing an exception: ' as in previous example, but set a timeout of 10 milliseconds |
Notice that all serviced components implement the IDisposable interface. A client should call Dispose as soon as the object isn't used any longer, because the Dispose method 's implementation of a serviced component maps to the ServicedComponent.DisposeObject shared method, which puts the disposed object back in the pool. Another technique for automatically put the object back to the pool when clients don't need it any longer, and that works without having the client explicitly call the Dispose method, is applying the JustInTimeActivation attribute to make the component support JIT activation. In this case COM+ puts the object back to the pool at the end of any method call that sets the "done" bit. This can be done very easily if you mark a method with the AutoComplete attribute: |
Click here to copy the following block | <JustInTimeActivation(True), ObjectPooling(True)> Public Class BankTransfer Inherits ServicedComponents <AutoComplete()> Sub Transfer(fromAccount As String, toAccount As String, _ Money As Decimal) End Sub
End Class |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|