主要原因是没有释放AO资源
public class Form1 : System.Windows.Forms.Form
{
private ESRI.ArcGIS.esriSystem.IAoInitialize m_AoInitialize = new ESRI.ArcGIS.esriSystem.AoInitializeClass();
private void Form1_Load(object sender, System.EventArgs e)
{
// 创建新的AoInitialize对象
if ( m_AoInitialize == null)
{
System.Windows.Forms.MessageBox.Show("初始化失败,程序不能运行!");
this.Close();
}
// 判断产品是否有效
ESRI.ArcGIS.esriSystem.esriLicenseStatus licenseStatus = (esriLicenseStatus)
m_AoInitialize.IsProductCodeAvailable(
ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeEngine);
if (licenseStatus == ESRI.ArcGIS.esriSystem.esriLicenseStatus.esriLicenseAvailable )
{
licenseStatus = (ESRI.ArcGIS.esriSystem.esriLicenseStatus)
m_AoInitialize.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeEngine);
if (licenseStatus != ESRI.ArcGIS.esriSystem.esriLicenseStatus.esriLicenseCheckedOut )
{
System.Windows.Forms.MessageBox.Show("初始化失败,应用程序不能运行!");
this.Close();
}
}
else
{
System.Windows.Forms.MessageBox.Show("ArcGIS Engine产品无效,此程序不能运行!");
this.Close();
}
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// 释放COM对象并关闭AoInitialize对象
ESRI.ArcGIS.Utility.COMSupport.AOUninitialize.Shutdown();
m_AoInitialize.Shutdown();
}
}