遅延バインドされたCOMオブジェクトを解放する方法は?
-
10-07-2019 - |
質問
レイトバインドされた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オブジェクトをリリースするにはどうすればよいですか?
解決
Marshal.ReleaseComObject を使用できます
e.g。
if(Marshal.IsComObject(oGE)==true)
{
Marshal.ReleaseComObject(oGE);
}
所属していません StackOverflow