Bagikan melalui


Hosting Overview

The .NET Framework version 2.0 enables applications that host the common language runtime (CLR) to control 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.

Note

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 Management Interfaces

In the .NET Framework version 2.0, the CLR provides hosting management interfaces to control many features of the hosted runtime, enables the host application to implement other management interfaces provided by the runtime, and lets you implement your own hosting management interfaces.

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

  • Management interfaces that the host implements and the runtime discovers through the IHostControl interface.

  • Management interfaces that the CLR provides and the host discovers through the ICLRControl interface.

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

Group

Function

Interfaces

Assembly loading management

Enables 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 CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostAssemblyManager

IHostAssemblyStore

ICLRAssemblyReferenceList

ICLRAssemblyIdentityManager

Policy management

Enables 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 management

Enables 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 management

Enables the host to control memory allocation by providing replacements for the operating system functions that the CLR uses to allocate memory.

The CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostMemoryManager

IHostMAlloc

ICLRMemoryNotificationCallback

Garbage collection management

Enables the host to implement methods to receive notification of the beginning and end of garbage collection. Enables 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 CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostGCManager

ICLRGCManager

Debug management

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

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

ICLRDebugManager

CLR event management

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

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

ICLROnEventManager

IActionOnCLREvent

Task management

Enables 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 CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostTaskManager

ICLRTaskManager

IHostTask

ICLRTask

Thread pool management

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

The CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostThreadPoolManager

Synchronization management

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

The CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostSyncManager

ICLRSyncManager

IHostCrst

IHostManualEvent

IHostAutoEvent

IHostSemaphore

I/O completion management

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

The CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostIoCompletionManager

Note

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

Application Domain Managers

For programs that host the CLR, application domains provide greater reliability by isolating assemblies from one another. 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

Concepts

Loading the Common Language Runtime into a Process

Reference

AppDomainManager

Other Resources

Hosting the Common Language Runtime

Application Domains

Hosting Interfaces for the .NET Framework 2.0 and Later