Page 1 of 1

COM Add-In: Close Instance?

Posted: Sat Feb 23, 2019 4:58 pm
by cazeek

Is there a way to close the instance of E-Views through the COM automation? Something like app.Close?


Re: COM Add-In: Close Instance?

Posted: Sat Feb 23, 2019 5:00 pm
by cazeek
Nevermind- after spending 30 min trying to figure this out, got it just as I posted (of course)...


Re: COM Add-In: Close Instance?

Posted: Mon Feb 25, 2019 8:44 am
by EViews Steve
Actually, running the EXIT command via COM can potentially cause problems with your COM objects in your application. You're asking EViews to shutdown, even though you still have an EViews Application object in your program and if you try to use that object again afterwards you'll most definitely get an exception.

The lifetime of a COM server (such as EViews) follows the basic rule that if anyone is using the application, it remains up and running. So any application objects you have in your application counts as a "user" -- and multiple variables counts as multiple "users". One special rule about this is that if the EViews application window is itself visible, that also counts as a "user". So, if you launch EViews via COM, and then call the Show method to make the application itself visible, and then your program shuts down, EViews will remain running since the application window is being shown and there might be a desktop user using it that way.

Hide EViews before your Program Ends
So the proper way to make sure EViews shuts down after you're done with it is to make sure the EViews application window is NOT visible when your program ends (by calling Application::Hide). Then once your program has released all EViews object references (namely the Application object), EViews will shutdown (usually within a few seconds).

NOTE: In some languages (such as .NET), the destruction of an object reference is handled by a separate garbage collector that runs in its own thread/process. This can cause a significant delay between clearing your last application object variable (such as setting it to null or Nothing) and seeing EViews shutdown. In these cases, your development environment might allow you to call explicitly call the garbage collector to run immediately and speed up this process.