Share via


IVsaEngine.Run Method

Initiates execution of compiled code in the script engine and binds all event handlers.

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

Remarks

Once this method has been called, the IVsaEngine.IsRunning property returns true until the script engine is stopped by a call to the IVsaEngine.Reset method or the IVsaEngine.Close method. While the script engine is running, no modifications can be made to the script engine, such as changing properties and adding or removing items. While the script engine is running, only the Reset or Close methods can be called, although most properties can be read.

Upon a call to the IVsaEngine.Run method, the engine evaluates the following conditions and proceeds accordingly:

  1. If the most recent call to IVsaEngine.Compile fails, an EngineNotCompiled exception is thrown;

  2. If there is compiled state loaded in the engine, this code is run;

  3. if not, and if there is compiled state in the code cache, this code is run;

  4. if not, and if a callback to IVsaSite.GetCompiledState returns compiled state, this code is run;

  5. if not, the call fails and a GetCompiledStateFailed exception is propagated from step 3.

If the script engine supports globally executable code, such as the JScript .NET script engine, or if the engine supports a well-known startup method such as Sub Main in Visual Basic, the global code is executed immediately. If execution of the global code results in an unhandled exception, the exception is propagated back to the host. Once initial global or startup code has been executed, the Run method returns control to the host and the assembly continues to run asynchronously until you call the Reset or Close methods.

Event sources and global objects, if any, are attached in such a way that they are directly accessible from running code. Upon calling the Run method, a callback to the IVsaSite.GetEventSourceInstance method will get instances of event source objects, and IVsaSite.GetGlobalInstance will get global objects.

The following table shows the exceptions that the Run 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.

EngineRunning

The engine is already running.

RootMonikerNotSet

The IVsaEngine.RootMoniker property has not been set.

SiteNotSet

The IVsaEngine.Site property has not been set.

AppDomainInvalid

The application domain is not valid (for example, it has been destroyed), or a new one could not be created.

GetCompiledStateFailed

There was no compiled state in the engine, and the callback to the IVsaSite.GetCompiledState method failed.

CachedAssemblyInvalid

The engine tried to use a cached assembly that is not a valid assembly.

See Also

Reference

IVsaEngine Interface

IVsaSite.GetEventSourceInstance Method

IVsaSite.GetGlobalInstance Method