Hi,
I have a web service that calls a COM object written in Uniface and
unfortunatley we don't have the opportunity to rewrite this component. This
COM object is not thread safe, in fact when two threads access the object it
will fail spectactularly! This is fine, I have created a class that only
allows one thread to call into the COM object at a time. The esyv0005Class
is the .NET Interop assembly created from our COM object.
internal class RequestBroker {
private static object mLock = new object();
........... more methods
private string InternalExecute(string parameters, string serviceName) {
lock (mLock) {
string resultXml;
ePathway.Request.Broker.esyv0005Class service = new
ePathway.Request.Broker.esyv0005Class();
service.exec(serviceName, parameters, out resultXml);
// The important lines here
// service = null;
// GC.Collect();
return resultXml;
}
}
}
If i leave the two lines commented out we rely on the GC to at its leisure
dispose of the interop object which intern will free the reference to the
underlying COM object. The problem with this is that our application fails
when stress tested because the object isn't being disposed of immediately
and we receive a dreaded Uniface -57 error. If I uncomment the calls to
GC.Collect() i then have a hell of alot of calls for the GC to do its thing,
especially underload.
Now the .Net interop class (esyv005Class) doesn't implement IDispose so
thats not a solution here, is there a way of having the interop object GC
immediately without the overhead of calling GC.Collect() ? I have tried
making the variable a member of the class and only instantiating the object
once, thereby eliminating the need to dispose of the object, however I
encountered periodic errors. Any other alternatives that you can see ?
tia
andrew