asp net 3.5unleashed

Page 455

Table 20-1: AppDomain Events Event Name

Description receives a string identifying the name of the missing resource.

TypeResolve

This event is fired when the CLR can’t locate a type required in one of the AppDomain’s assemblies. The handler receives a string identifying the name of the missing type and can tell the CLR what type to use by returning a reference to a Type object. Frequently, the handler decides what Type object to return based on the client’s location or operating system.

Applications and How They Host the CLR and Manage AppDomains So far, I’ve talked about hosts and how they load the CLR, AppDomains, and how the host can tell the CLR to create and unload AppDomains. To make the discussion more concrete, I thought I’d describe some common hosting and AppDomain scenarios. In particular, I’ll explain to you how different application types host the CLR and how they manage AppDomains.

Console and Windows Forms Applications When invoking a managed console or Windows Forms application, the shim examines the CLR header information contained in the application’s assembly. The header information indicates what version of the CLR was used to build and test the application. The shim uses this information to determine which CLR COM server to create. After the CLR loads and initializes, it again examines the assembly’s CLR header to determine which method is the application’s entry point (Main). The CLR invokes this method, and the application is now up and running. As the code runs, it accesses other types. When referencing a type contained in another assembly, the CLR locates the necessary assembly and loads it into the same AppDomain. Any additionally referenced assemblies also load into the same AppDomain. When the application’s Main method returns, the default AppDomain unloads and the Windows process terminates. Note By the way, you can call System.Environment’s static Exit method if you want to shut down the Windows process, including all its AppDomains. Exit is the most graceful way of terminating a process because it first calls the Finalize methods of all the objects on the managed heap and then releases all the unmanaged COM objects held by the CLR. Finally, Exit calls the Win32 ExitProcess function. It’s possible for a console or Windows Forms application to tell the CLR to create additional AppDomains in the process’s address space. However, these application types rarely ever use or require multiple AppDomains.

ASP.NET Web Forms and XML Web Services Applications


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.