0

遅延バインドされた COM オブジェクトも解放する必要があると思います。
しかし、これはどのように直接行われるのでしょうか?

私の状況では、C# から次のコードを使用して、Google Earth からフォーカス ポイントを取得します (簡略化)。

Type oClassType = Type.GetTypeFromProgID("GoogleEarth.ApplicationGE");
object oGE = Activator.CreateInstance(oClassType);
object oCamera = oGE.GetType().InvokeMember("GetCamera", System.Reflection.BindingFlags.InvokeMethod, null, oGE, new object[] { 0 });
double dFocusLatitude = (double)oCamera.GetType().InvokeMember("FocusPointLatitude", System.Reflection.BindingFlags.GetProperty, null, oCamera, null);
double dFocusLongitude = (double)oCamera.GetType().InvokeMember("FocusPointLongitude", System.Reflection.BindingFlags.GetProperty, null, oCamera, null);

では、この状況でカメラと Google Earth オブジェクトを解放するにはどうすればよいでしょうか?

4

1 に答える 1

6

Marshal.ReleaseComObjectを使用できます

例えば

if(Marshal.IsComObject(oGE)==true)
{
  Marshal.ReleaseComObject(oGE);
}
于 2009-08-03T14:16:18.000 に答える