Share via


IVsaEngine.Reset Method

Removes the script engine from the running state and disconnects automatically bound event handlers.

public: void Reset();
public void Reset();
MustOverride Public Sub Reset()

Remarks

Upon calling the Reset method, the event handlers no longer respond to events from the host, and the IVsaEngine.IsRunning property returns false. The Reset method also unloads the application domain set by the script engine in cases where one has been provided on behalf of an unmanaged host.

Warning

Calling IVsaEngine.Reset 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 Reset method has been called. (The same is true for IVsaEngine.Close.) This may create a security exposure, as hosts may incorrectly consider themselves safe from malicious code following a call to the Reset (or Close) 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.

The Reset method disconnects automatically bound event handlers, but does not disconnect those that you explicitly created.

The Reset method does not change the compiled state of the script engine; there is no need to call the IVsaEngine.Compile method again before calling the IVsaEngine.Run method unless the source state has changed. The IVsaEngine.Close method will automatically call the Reset method if it has not already been called.

The script engine must be in the running state; that is, the IVsaEngine.IsRunning property must return true before calling this method. Upon calling Reset, the IVsaEngine.Assembly property is set to a null reference, and Assembly objects that were retrieved using this property are no longer valid.

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

Exception Type

Condition

EngineClosed

The IVsaEngine.Close method has been called and the engine is closed.

EngineBusy

The engine is currently executing code for another thread.

EngineNotRunning

The engine is not currently running, that is, the IVsaEngine.IsRunning property returns false.

EngineCannotReset

The engine cannot be reset for some reason.

See Also

Reference

IVsaEngine Interface