C# Source Code: Re: A generic object pooling abstract base class (thread safe)
[
Home
|
Contents
|
Search
|
Reply
|
Previous
|
Next
]
C# Source Code
Re: A generic object pooling abstract base class (thread safe)
By:
heinz roth
Email (spam proof):
Email the originator of this post
Date:
Monday, August 27, 2007
Hits:
1077
Category:
Threading/Asynchronous operations
Article:
in your GetObject() method, you iterate through the objects in the pool and return the first one available. If you happen to encounter one which isn't available you remove it from the pool (which is ok)BUT then simply dispose it! why would you do that - it's in use and probably currently processing or am I missing something? foreach (DictionaryEntry de in keys) { htv = (HashTableValue) _objectsAvailable[de.Key]; //Validate object if (IsAvailable(htv.PoolObject)) { //Object is free for use, remove object from available pool _objectsAvailable.Remove(htv.PoolId); //Add object to in use pool _objectsInUse.Add(htv.PoolId, htv); //Return object return htv.PoolObject; } else { //Object unavailable, remove it _objectsAvailable.Remove(htv.PoolId); //Dispose of object DisposeObject(htv.PoolObject); htv.PoolObject = default(T); } }
Terms and Conditions
Support this site
Download a trial version of the best FTP application on the internet