Export (0) Print
Expand All

IVsaEngine.Close Method

Closes the script engine and releases all resources. If the script engine is currently running, the IVsaEngine.Reset method is called first.

[Visual Basic]
Sub Close()
void Close();
void Close();
function Close();


If the script engine is running at the time you wish to call the Close method, the script engine calls the IVsaEngine.Reset method for you. At this point, the compiled form of the code, all items added to the script engine, the internal state of the engine, and references to external objects are released. No other methods can be called on the script engine after it has been closed. Therefore, the Close method should only be called when the script engine is no longer needed and is about to be released.

CAUTION   Calling IVsaEngine.Close stops automatically-bound events from firing, but does not necessarily stop user code from running, as there may be code running on a timer, or there may be manually bound events still firing. In both scenarios, code will continue to run even after the Close method has been called. (The same is true for IVsaEngine.Reset.) This may create a security exposure, as hosts may incorrectly consider themselves safe from malicious code following a call to the Close (or Reset) method. The only way to be certain that no user code is running is to unload the application domain by calling System.AppDomain.Unload(myDomain), which unloads the assembly. Because managing application domains can be difficult, hosts should err on the side of caution and always assume malicious user code is running. For more information, see Using Application Domains.

If you are using the VSA design-time interfaces, do not hold pointers to the IVsaIDE interface after calling the Close method on the last open project.

The following table shows the exceptions that the Close method can throw.

Exception Type Condition
EngineClosed The Close method has been called and the engine is closed.
EngineBusy The engine is currently executing code for another thread.
EngineCannotClose The engine cannot be closed; for example, a reference held by the engine could not be released.


The following example shows how to close a script engine:

// Close the script engine.
// Release the script engine.
myEngine = null;


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

IVsaEngine Interface | IVsaEngine Members | Microsoft.Vsa Namespace | IVsaEngine.Reset

© 2015 Microsoft