¿Cómo liberar objetos COM vinculados tarde?
-
10-07-2019 - |
Pregunta
Supongo que tengo que liberar también objetos COM vinculados tarde.
Pero, ¿cómo se hace esto directamente?
En mi situación, uso el siguiente código de C # para obtener el punto focal de Google Earth (simplificado):
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);
Entonces, ¿cómo libero la cámara y los objetos de Google Earth en esta situación?
Solución
Puede usar Marshal.ReleaseComObject
por ejemplo
if(Marshal.IsComObject(oGE)==true)
{
Marshal.ReleaseComObject(oGE);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow