Tuesday, September 9, 2008
Release References to GeoMedia COM Objects in C#
When developing Driving GeoMedia custom applications using .NET, if you don't free up the references to GeoMedia objects, you will encounter the above error message when exiting your custom application. As GeoMedia objects are built as Windows COM (Common Object Model) objects, the .NET framework garbage handling facility will not automatically close and free up all the references to the GeoMedia objects. You will have to do an explicit COM object release using the .NET System.Runtime.InteropServices.Marshal class' FinalReleaseComObject method.
For example in your GeoMedia Wraper class' destructor you could code the following:
using System.Runtime.InteropServices;
using GeoMedia = Intergraph.GeoMedia.GeoMedia;
class GeoMediaWrapper
{
private GeoMedia.Application _application = null;
public GeoMediaWrapper()
{
Type GeoMediaType = Type.GetTypeFromProgID("GeoMedia.Application", "localhost", true);
this._application = (GeoMedia.Application) Activator.CreateInstance(GeoMediaType);
}
~GeoMediaWrapper()
{
if (this._application != null)
Marshal.FinalReleaseComObject (this._application);
}
//.... etc ...
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment