Tài liệu Module 2: Introduction to a Managed Execution Environment ppt

40 617 1
Tài liệu Module 2: Introduction to a Managed Execution Environment ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Contents Overview 1 Writing a .NET Application 2 Compiling and Running a .NET Application 11 Lab 2: Building a Simple .NET Application 29 Review 32 Module 2: Introduction to a Managed Execution Environment Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.  2001-2002 Microsoft Corporation. All rights reserved. Microsoft, ActiveX, BizTalk, IntelliMirror, Jscript, MSDN, MS-DOS, MSN, PowerPoint, Visual Basic, Visual C++, Visual C#, Visual Studio, Win32, Windows, Windows Media, and Window NT are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Module 2: Introduction to a Managed Execution Environment iii Instructor Notes After completing this module, students will be able to: ! Create simple console applications in C#. ! Explain how code is compiled and executed in a managed execution environment. ! Explain the concept of garbage collection. Materials and Preparation This section provides the materials and preparation tasks that you need to teach this module. Required Materials To teach this module, you need the following materials: ! Microsoft ® PowerPoint ® file 2349B_02.ppt ! Sample managed module HelloDemoCS.exe Preparation Tasks To prepare for this module, you should: ! Read all of the materials for this module. ! Practice the demonstrations. ! Review the animation. ! Complete the lab. Presentation: 45 Minutes Lab: 20 Minutes iv Module 2: Introduction to a Managed Execution Environment Demonstrations This section provides demonstration procedures that will not fit in the margin notes or are not appropriate for the student notes. Hello World This demonstration shows how to build a simple application in C#. In the following procedures, use Notepad to create the simple Hello World application, and build and run the HelloDemoCS.exe application from the command line. ! To create the source code in C# 1. Open Notepad and type the following code: // Allow easy reference to System namespace classes using System; // Create class to hold program entry point class MainApp { public static void Main() { // Write text to the console Console.WriteLine(“Hello World using C#!”); } } 2. Save the file as HelloDemoCS.cs. To use Microsoft Visual Studio ® .NET tools within a command prompt window, the command prompt window must have the proper environment settings. The Visual Studio .NET Command Prompt window provides such an environment. To run a Visual Studio .NET Command Prompt window, click Start, All Programs, Microsoft Visual Studio .NET, Visual Studio .NET Tools, and Visual Studio .NET Command Prompt. Important Module 2: Introduction to a Managed Execution Environment v ! To compile the source code and build an executable program • From a Visual Studio .NET Command Prompt window, type the following syntax: csc HelloDemoCS.cs Running the resulting executable file will generate the following output: Hello World using C#! Viewing Assembly Metadata by Using the MSIL Disassembler This demonstration shows how to use the Microsoft Intermediate Language (MSIL) Disassembler (Ildasm.exe) to view an assembly’s metadata. The code for this demonstration is contained in one project and is located in <install folder>\Democode\Mod02. To demonstrate how to use the MSIL Disassembler to view the contents of the HelloDemoCS.exe assembly, follow the directions in Demonstration: Using the MSIL Disassembler in this module. vi Module 2: Introduction to a Managed Execution Environment Multimedia This section lists the multimedia items that are part of this module. Instructions for launching and playing the multimedia are included with the relevant slides. Application Loading and Single-File Assembly Execution This animation will show students how a single-file private assembly is loaded and executed. Module Strategy Use the following strategy to present this module: ! Writing a .NET Application Stress the importance of understanding the process of compiling and running Microsoft .NET Framework applications, by using the simple Hello World application. Focus primarily on the compilation and execution processes. ! Compiling and Running a .NET Application This section introduces basic concepts of a managed execution environment and presents new terminology. Many of these concepts are covered in greater detail in subsequent modules in this course, in subsequent courses, and in the .NET Framework software development kit (SDK) documentation. Emphasize that you are primarily introducing new concepts and terminology. Be prepared to postpone answering questions that pertain to information that is covered in later modules. Encourage students to start reading the .NET Framework SDK documentation. Module 2: Introduction to a Managed Execution Environment 1 Overview ! Writing a .NET Application ! Compiling and Running a .NET Application ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** This module introduces the concept of managed execution and shows you how to quickly build applications that use the Microsoft ® .NET Framework common language runtime environment. A simple Hello World version of a console application illustrates most of the concepts that are introduced in this module. Because this course is an introduction to programming in the .NET Framework, you should spend some time reading the .NET Framework software development kit (SDK) documentation. In fact, the labs, demonstrations, and material for this module and other modules in this course are based on several tutorials in the .NET Framework SDK. After completing this module, you will be able to: ! Create simple console applications in C#. ! Explain how code is compiled and executed in a managed execution environment. ! Explain the concept of garbage collection. Topic Objective To provide an overview of the module topics and objectives. Lead-in This module introduces the concept of managed execution and shows you how to quickly build applications that use the Microsoft .NET Framework common language runtime environment. 2 Module 2: Introduction to a Managed Execution Environment " "" " Writing a .NET Application ! Using a Namespace ! Defining a Namespace and a Class ! Entry Points, Scope, and Declarations ! Console Input and Output ! Case Sensitivity ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** Because all supported languages use the Common Type System and the .NET Framework base class library, and run in the common language runtime, programs in the supported languages are similar. The most significant difference in programming with the supported languages is syntax. In this module, and in Modules 3 and 4, Notepad is used as the source code editor, instead of the Microsoft Visual Studio ® .NET development environment. The examples in these modules are simple enough to be compiled and built directly from a command prompt window. Working in Notepad will allow you to focus on the compilation and execution processes. Topic Objective To introduce the topics in the section. Lead-in Because all supported languages use the Common Type System and the .NET Framework class library, and run in the common language runtime, programs in the supported languages are similar. Delivery Tip Stress the importance of understanding the process of compiling and running the .NET applications. Using Visual Studio .NET at this time may obscure the underlying processes. Note Module 2: Introduction to a Managed Execution Environment 3 Demonstration: Hello World ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** In this demonstration, you will learn how to build a simple application in C#. ! To create the source code in C# 1. Open Notepad and type the following code: // Allow easy reference to System namespace classes using System; // Create class to hold program entry point class MainApp { public static void Main() { // Write text to the console Console.WriteLine(“Hello World using C#!”); } } 2. Save the file as HelloDemoCS.cs Topic Objective To demonstrate how to build a simple application in C#. Lead-in In this demonstration, you will learn how to build a simple application in C#. Delivery Tip As this is a short, simple demonstration, you may want to let students try it themselves. 4 Module 2: Introduction to a Managed Execution Environment ! To compile the source code and build an executable program To use Visual Studio .NET tools within a command prompt window, the command prompt window must have the proper environment settings. The Visual Studio .NET Command Prompt window provides such an environment. To run a Visual Studio .NET Command Prompt window, click Start, All Programs, Microsoft Visual Studio .NET, Visual Studio .NET Tools, and Visual Studio .NET Command Prompt. • From a Visual Studio .NET Command Prompt window, type the following syntax: csc HelloDemoCS.cs Running the resulting executable will generate the following output: Hello World using C#! Important [...]... impossible to separate metadata from the MSIL code Module 2: Introduction to a Managed Execution Environment 17 Uses for Metadata Metadata has many uses, but the following uses are most important: ! Locating and loading classes Because metadata and MSIL are included in the same file, all type information in that file is available to the common language runtime at compile time There is no need for header... platform-specific native APIs or libraries can only run on a specific operating system For more information about MSIL, see the NET Framework SDK documentation Module 2: Introduction to a Managed Execution Environment 19 Assemblies Topic Objective This topic introduces the concept of an assembly and the role of the assembly manifest Managed Module Managed Module (MSIL and Metadata) (MSIL and Metadata) Managed Module. .. processes The ability to run multiple applications within a single process dramatically increases server scalability 26 Module 2: Introduction to a Managed Execution Environment Isolating applications is also important for application security For example, you can run controls from several Web applications in a single browser process in such a way that the controls cannot access each other's data and resources... uses an assembly as the functional unit of sharing and reuse Definition of an Assembly An assembly is a unit of class deployment, analogous to a logical dll Each assembly consists of all the physical files that make up the functional unit: any managed modules, and resource or data files Conceptually, assemblies provide a way to consider a group of files as a single entity You must use assemblies to build... build an application, but you can choose how to package those assemblies for deployment An assembly provides the common language runtime with the information that it needs to understand types and their implementations As such, an assembly is used to locate and bind to referenced types at run time 20 Module 2: Introduction to a Managed Execution Environment The Assembly Manifest An assembly contains a. .. versatile unit of processing that the common language runtime can use to provide isolation between applications Application domains are typically created by runtime hosts, which are responsible for bootstrapping the common language runtime before an application is run 16 Module 2: Introduction to a Managed Execution Environment Metadata Topic Objective To explain how metadata is used in the common language... tasks because the consequences of the errors are unpredictable Memory Management in the NET Framework The common language runtime uses a heap called the managed heap to allocate memory for all objects This managed heap is similar to a C-Runtime heap, however you never free objects from the managed heap In the common language runtime, garbage collection is used to manage memory deallocation The garbage collection... used to isolate applications running on the same computer ! Historically, Process Boundaries Used to Isolate Applications ! In the Common Language Runtime, Application Domains Provide Isolation Between Applications # # ! The ability to verify code as type-safe enables isolation at a much lower performance cost Several application domains can run in a single process Faults in One Application Cannot Affect... *****************************ILLEGAL FOR NON-TRAINER USE****************************** Every compiler that targets the common language runtime is required to emit full metadata into every managed module This topic explains how the common language runtime uses metadata Definition of Metadata Metadata is a set of data tables, which fully describe every element that is defined in a module This information can include data types and... The MSIL Disassembler You can use the MSIL Disassembler (Ildasm.exe) to examine the metadata and disassembled code of any managed module You will use this tool to examine MSIL code in Lab 2, Building a Simple NET Application 22 Module 2: Introduction to a Managed Execution Environment Demonstration: Using the MSIL Disassembler Topic Objective To demonstrate how the MSIL Disassembler works Lead-in This . Writing a .NET Application 2 Compiling and Running a .NET Application 11 Lab 2: Building a Simple .NET Application 29 Review 32 Module 2: Introduction to a Managed. a managed execution environment. ! Explain the concept of garbage collection. Materials and Preparation This section provides the materials and preparation

Ngày đăng: 09/12/2013, 17:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan