Monday 9 January 2012

Introduction


  We all know that there have been disparities between different languages such as VB, VC++ and developers, who code program through these languages. The disparity lies in terms of language features, performance, and flexibility in developing any piece of program. Well it’s a known fact that, at the end, what matters is how efficiently your  programs run on the client machine, no matter what language you use. Earlier this was driven by compilers, which were used to compile the code written using these languages to make it native code (processor specific).
   With the release .NET framework Microsoft has driven out the disparities in such a way that no matter whatever .NET language you use to develop .NET applications, still the end result will be determined by .NET framework runtime and not by the language compilers as it was happening earlier. In this tutorial we will identify some of the key elements of the .NET framework through a simple program and concentrate on how
.NET framework Runtime addresses platform or processor specific code issues to produce optimized code, which is native to the processor and to know how the framework helps in managing code effectively.

Common Language Runtime (CLR)
   The primary function of a runtime is to support and manage the execution of code targeted for a language or a platform. For example, the Microsoft VC++ requires the msvcrt60.dll that contains its core support functionality. Even languages like Java have a run time, in the form of  Java Virtual Machine.
   The .Net platform also comes with a runtime that is officially called as the Common Language Runtime or simply the CLR. The CLR is designed to support a variety of different types of applications, from Web server applications to applications with traditional rich Windows user interface. Though the role of the CLR is similar to its counterparts in other languages or platforms, there are some key differences that make it one of the major features of the .NET platform. Here are the key differences between the .NET CLR and runtime of other languages:
• It is a common runtime for all languages targeting the .NET platform.
• It acts as an agent that manages code at execution time and also provides core services such as memory management, thread management and remoting.
• It enforces strict type safety and other forms of code accuracy that ensure security and robustness.
• It is responsible for enabling and facilitating the Common Type System. The Common Type System allows classes that are written in any .NET language to interoperate with—even inherit from, with overrides—classes written in any language. So your COBOL.NET program can interoperate with your C#, VB.NET,
Eiffel.NET and with any other .NET language programs.
• It offers a mechanism for cross-language exception handling.
• It provides a more elegant way for resolving the versioning issues (also referred to as the Dll Hell in our classic COM).
• It provides a simplified model for component interaction.

     Code that targets the runtime is known as managed code, while code that does not target the runtime is known as unmanaged code. Managed code requires a runtime host to start it. The responsibility of the runtime host is to load the runtime into a process, create the application domains (we’ll look at this in detail later) within the process, and loads the user code into the application domains. While we can write our own runtime hosts using the set of APIs provided by Microsoft, the .NET platform by default ships with runtime
hosts that include the following.
ASP.NET – Loads the runtime into the process that is to handle the Web request. ASP.NET also creates an application domain for each Web application that will run on a Web server.
Microsoft Internet Explorer – Creates application domains in which to run managed controls. The .NET Framework supports the download and execution of browser-based controls. The runtime interfaces with the extensibility mechanism of Microsoft Internet Explorer through a mime filter to create application domains in which to run the managed controls. By default, one application domain is created for each Web site.
Shell executables – Invokes runtime hosting code to transfer control to the runtime each time an executable is launched from the shell.
   Now that you have understood conceptually the key features of the CLR in .NET framework, you can begin to look into the physical implementation and execution of code in the CLR.