Compartir a través de


Hosting Overview 

The .NET Framework version 2.0 provides applications that host the common language runtime with control over many features of the runtime. You can replace some features, such as memory allocation and assembly loading, with custom implementations. You can control the behavior of other features, receive notifications of events in the runtime, and manage application domains.

Initializing and Starting a Hosted Runtime

As with earlier versions of the runtime, the CorBindToRuntimeEx function initializes the runtime. You can choose which version of the runtime to load, but a process can host only one version. If version 2.0 is loaded, the function returns the ICLRRuntimeHost interface, which is used to start the runtime and execute managed code.

NoteNote

In earlier versions, the ICorRuntimeHost interface is returned.

Starting the runtime is discussed in Loading the Common Language Runtime into a Process and executing managed code is discussed in Transitioning to Managed Hosting Code.

Hosting Managers

In the .NET Framework version 2.0, the common language runtime provides hosting managers to control many features of the hosted runtime, and allows the host application to implement other managers. See Hosting Interfaces for the .NET Framework 2.0 for descriptions of the COM interfaces you can use to interact with the managers provided by the runtime, and to implement your own hosting managers.

The following table groups the interfaces by the kind of functionality they provide. The most important interface for each manager is listed first.

Manager Function Interfaces

Assembly Loading Manager

Allows the host to customize the locations from which assemblies are loaded, the way versions are managed, and the formats from which assemblies can be loaded. For example, assemblies could be loaded from a database instead of from files on the hard disk.

The common language runtime uses the IHostControl interface to discover whether a host implements this manager.

IHostAssemblyManager

IHostAssemblyStore

ICLRAssemblyReferenceList

ICLRAssemblyIdentityManager

Policy Manager

Allows the host to specify the way program failures are handled, to support different reliability requirements.

The host uses the ICLRControl interface to gain access to the runtime manager, and implements IHostPolicyManager callbacks for failure notifications from the runtime.

ICLRPolicyManager

IHostPolicyManager

Host Protection Manager

Allows the host to enforce its own programming model, by preventing the use of specified types or members. For example, the host can disallow the use of threading or synchronization primitives.

The host uses the ICLRControl interface to gain access to the runtime manager.

ICLRHostProtectionManager

Memory Manager

Allows the host to control memory allocation by providing replacements for the operating system functions the common language runtime uses to allocate memory.

The common language runtime uses the IHostControl interface to discover whether a host implements this manager.

IHostMemoryManager

IHostMAlloc

ICLRMemoryNotificationCallback

Garbage Collection Manager

Allows the host to implement methods to receive notification of the beginning and end of garbage collection. Allows the host to initiate collections, to collect statistics, and to specify some characteristics of collection.

The host uses the ICLRControl interface to gain access to the runtime manager. The common language runtime uses the IHostControl interface to discover whether a host implements this manager.

IHostGCManager

ICLRGCManager

Debug Manager

Allows the host to discover whether a debugger is attached, to provide additional debugging information, and customize debugging tasks.

The host uses the ICLRControl interface to gain access to the runtime manager.

ICLRDebugManager

Common Language Runtime Event Manager

Allows a host to register for notification of the events enumerated by EClrEvent.

The host uses the ICLRControl interface to gain access to this manager, and implements its event handlers using IActionOnCLREvent.

ICLROnEventManager

IActionOnCLREvent

Task Manager

Allows the host to be notified whenever a thread makes a transition between managed and unmanaged code. Allows the host to control thread affinity, when tasks are started and stopped, and how they are scheduled.

The common language runtime uses the IHostControl interface to discover whether a host implements this manager.

IHostTaskManager

ICLRTaskManager

IHostTask

ICLRTask

Thread Pool Manager

Allows the host to implement its own thread pool for the runtime to use.

The common language runtime uses the IHostControl interface to discover whether a host implements this manager.

IHostThreadPoolManager

Synchronization Manager

Allows the host to implement its own synchronization primitives for the runtime to use. The host can provide events, critical sections, and semaphores.

The common language runtime uses the IHostControl interface to discover whether a host implements this manager.

IHostSyncManager

ICLRSyncManager

IHostCrst

IHostManualEvent

IHostAutoEvent

IHostSemaphore

I/O Completion Manager

Allows the host to implement its own implementation of asynchronous input/output.

The common language runtime uses the IHostControl interface to discover whether a host implements this manager.

IHostIoCompletionManager

NoteNote

The hosting interfaces for earlier versions of the runtime are documented in Hosting Interfaces for the .NET Framework 1.0 and 1.1.

For purposes of discovery, the managers fall into two broad categories:

  • Managers the host implements, and the runtime discovers through the IHostControl interface.

  • Managers the common language runtime provides, and the host discovers through the ICLRControl interface.

Application Domain Managers

For programs that host the common language runtime, application domains provide greater reliability by isolating assemblies from each other. Assemblies can be unloaded from the process by unloading application domains.

To manage multiple application domains, the .NET Framework version 2.0 provides the AppDomainManager class as a base class from which you can derive your own application domain managers. The application domain manager you design for your host application is essentially an extension of the host, in managed code. It is automatically loaded into each application domain created in your process.

The application domain manager can improve performance by eliminating some transitions between managed and unmanaged code. It can receive notification of the creation of new application domains, giving you an opportunity to configure them. It also provides an unmanaged host with a way to call managed code.

See Also

Reference

AppDomainManager

Concepts

Loading the Common Language Runtime into a Process

Other Resources

Hosting the Common Language Runtime
Application Domains
Hosting Interfaces for the .NET Framework 2.0