Now, the unmanaged portion of CLR host has loaded the CLR
into the process. A default domain is created automatically by the CLR after it
is loaded into the process. This default domain will be unloaded only after the
process shuts down. This is the reason that most hosts do not run user code in
the default domain as it cannot be shut down independently of the process. The
ICorRuntimeHost is the interface that exposes some methods for creating
application domains and unloading the same. Let us discuss some of the
important methods of ICorRuntimeHost in detail. This will help us to understand
ICorRunimeHost in a better manner.
Method Name
|
Description
|
CreateDomain
|
Creates an application domain. Gets an interface pointer
of type System._AppDomain. Takes a friendly name of the Application domain.
|
CreateDomainEx
|
Creates an application domain. This method extends the
functionality of the CreateDomain method by allowing the caller to pass the
instance of IAppDomainSetup. IAppDomainSetup provides properties that allow
the host to configure an AppDomain before calling
ICorRuntimeHost::CreateDomainEx to create it. It has properties like
ApplicationBase, Application Name, LicenseFile, etc.
|
Start
|
Starts the common language runtime.
|
Stop
|
Unloads the common language runtime from the current
process.
|
UnloadDomain
|
Unloads the application domain represented by pAppDomain
from the current process. Takes the reference of the application domain as
the parameter.
|
EnumDomains
|
Returns an enumerator for the domains in the current
process.
|
CurrentDomain
|
Returns an interface pointer to the AppDomain running on
the current thread.
|
NextDomain
|
Returns an interface pointer to the next domain in the
enumeration. Takes the EnumDomains as the parameter.
|
GetDefaultDomain
|
Returns an interface pointer of type _AppDomain,
representing the default domain for the current process.
|
ICLRRunTimeHost is the interface developed for the CLR
version 2.0. This interface is the superseded interface of ICorRuntimeHost. This
interface has a new method called as SetHostControl. SetHostControl must be
called before the common language runtime is initialized, that is, before a
call to the Start method. It is always recommended to call SetHostControl
immediately after a call to CorBindToRuntimeEx [Unmanaged API].