I decided to put in explicit handling to kill the GeoMedia process in my class' constructor and destructor. The basic idea is to get the process id of my custom application's GeoMedia instance in the constructor. Then when exiting the custom application in the class' destructor, I use the process id to kill off the GeoMedia process.
The C# code listing below illustrates the basic idea.
using System;
using System.Collections;
using System.Diagnostics;
using GeoMedia = Intergraph.GeoMedia.GeoMedia;
class GeoMediaWrapper
{
private int _myProcessId; //my GeoMedia process id
private GeoMedia.Application _application;
public GeoMediaWrapper()
{
Type GeoMediaType;
//Build an array list of all running GeoMedia
//processes first
ArrayList processList = new ArrayList();
foreach (Process proc in Process.GetProcessesByName("GeoMedia"))
processList.Add(proc.Id);
//Start up an instance of GeoMedia
GeoMediaType = Type.GetTypeFromProgID("GeoMedia.Application", "localhost", true);
this._application = (GeoMedia.Application)Activator.CreateInstance(GeoMediaType);
//Loop through all the running GeoMedia processes.
//If the id does not exist in the previously built list,
//then this must be my GeoMedia process id number.
foreach (Process proc in Process.GetProcessesByName("GeoMedia"))
if (!GMProcs.Contains(proc.Id))
{
//this is my GeoMedia process!
this._GMProcId = proc.Id;
}
}
~GeoMediaWrapper()
{
//Kill off my GeoMedia process
Process.GetProcessById(this._GMProcId).Kill();
}
//...etc...
}
No comments:
Post a Comment