0% found this document useful (0 votes)
30 views10 pages

Ch 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views10 pages

Ch 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Chapter Two

Introduction to .NET
2.1 The .NET Platform and Its Architecture

The development of .Net has been started in the late 90’s with the development of .Net Framework only originally
under the name of NGWS (Next Generation Windows Services).
The .NET framework is Microsoft’s Managed code programming model for building applications on Windows
clients, servers and mobile or embedded devices. Microsoft’s .NET framework is a software technology that is
available with several Microsoft windows operating systems. The Microsoft .NET framework is a platform that
provide tools and technologies you need to build networked applications as well as distributed web services and
web applications. The .Net framework provides the necessary compile time and run-time foundation to build and
run any language that conforms to the Common Language Runtime (CLR) and .Net Framework Class Library
(FCL).
C++ VB C# …

ASP.NET
Windows

Visual Studio .NET


Web Forms Web Services Forms
Mobile Internet Toolkit

ADO.NET and XML

Base Class Library

Common Language Runtime (CLR)

Operating system

.NET Framework Architecture

The .Net Framework Architecture is the programming model for the .Net platform. It provides a managed
execution environment, simplified development and deployment and integration with a wide variety of
programming languages.

2.1.1 Base Class Library (BCL)

A library is a set of reusable functionality. In every programming languages we are provided with these libraries.
But in our earlier languages,libraries of the languages are specific to that language only. Whereas in .Net, all
languages are provided with the same set of libraries what we call as BCL which can be consumed in any .Net
language.

Event driven programming 1 2023


Base Class Libraries are implemented in C# language and being consumed from various .Net languages so this can
be taken as a good example for language interoperability.

2.1.2 Common Language Runtime

The Common Language Runtime (CLR) is the runtime environment of the .Net Framework that executes and
manages all the running code like a virtual machine. It works as a layer between Operating systems and the
applications written in .Net languages that conforms to the Common Language Specification (CLS).

Microsoft .Net languages source code are compiled into Microsoft Intermediate Language (MSIL). MSIL we can
call it as Intermediate Language (IL) or Common Intermediate Language (CIL). MSIL is a CPU independent set of
instructions that can be converted to the native code. Metadata is also created in the course of compile time with
MSIL and stored it with the compiled code. Metadata is completely self-describing. Metadata is stored in a file
called Manifest and it contains information about members, types, references and all other data the Common
Language Runtime (CLR) needs for execution. The Common Language Runtime (CLR) uses metadata to locate
and load classes, generate native code and provide security and execute Managed code. Portable Executable (PE)
is the file format defining the structure that all executable files (EXE) and Data Link Libraries (DLL) must use to
allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format
(COFF). The EXE and DLL files created using the .Net Framework obey the PE/COF formats and also adds
additional headers and data sections to the files that are only used by the CLR. Portable Executable (PE) file is
supposed to be portable across all 32-bit operating systems by Microsoft .Net Framework.

During the runtime the CLR’s Just In Time (JIT) compiler converts the MSIL code into native code to the
operating system. The native code is operating system independent and this code is known as managed code, that
is, the language functionality is managed by the .Net Framework.

Event driven programming 2 2023


At the time of program execution, the Common Language Runtime (CLR) manages memory using Garbage
Collection (GC), Thread execution, Exception handling, Common Type System (CTS), code safety verifications
and other system services.

The CLR contains the following various things under it.

i. Security Manager: it takes the responsibility of application security


ii. Class Loader: this is responsible in loading the require libraries for execution of the program from the Base
Libraries.
iii. JIT (Just In Time): JIT compiler, which compiles MSIL into native code.
JIT are of three types: Pre-JIT, Econo-JIT and Normal-JIT.
Pre-JIT: In Pre-JIT compilation, the complete source code are converted into native code in a single
cycle. This is done at the time of application deployment.
Econo-JIT: In Econo-JIT, the compiler compiles only those methods which are called at runtime. After
execution of these methods, compiled methods are removed from memory.
Normal-JIT: In Normal-JIT, the compiler compiles only those methods which are called at runtime.
After execution of these methods, compiled methods are stored in memory. Now further calling to
compiled method will execute the method from memory cache.
iv. Garbage Collector: This is responsible for automatic memory management. Memory management is the
process of allocation and de-allocation of memory, that is required for a program, which is of two
types:
- Explicit/Manual memory management –programmers are responsible for allocation and de-
allocation of memory for their program.
- Implicit/Automatic memory management – Garbage Collector is responsible for memory
management which is required in our program.
v. Execution manager: this is responsible to care of Run time errors that occur in our program.

Benefits of CLR:
 It improves the performance by providing a richly interact between programs at the run time.
 Enhance portability by removing the need of recompiling a program on any operating system that
supports it.
 Security also increases as it analyzes the MSIL instructions whether they are safe or unsafe. Also, the
use of delegates in place of function pointers enhance the type safety and security.
 Support automatic memory management with the help of Garbage Collector.
 Provides cross-language integration because CTS inside CLR provides a common standard that activates
the different languages to extend and share each other’s libraries.
 Provides support to use the components that developed in other .NET programming languages.
 Provide language, platform, and architecture independency.
 It allows the creation of the scalable and multithreaded applications in an easier way as a developer has
no need to think about the memory management and security issues.

Event driven programming 3 2023


Note: Microsoft .Net Framework is proprietary Windows software and requires the Windows API to run. It will
not run natively in Linux. But there is an open source implementation of .NET Framework called MONO which
has almost the same functionality of the MS .NET.

2.2 Uses of .NET Platform in Application Development

The success or failure for any project or product in the market is decided by its return on investment. Both the
quantum of profits and time taken are important aspects of calculating Return On Investment (ROI). The following
features of .NET facilitate reduction of developmental and operational cost for an efficient IT organization.

i. Less coding and increased reuse of code: This framework works on object-oriented programming which
eliminates unnecessary coding for the developers. .Net consists of reusable code and many reusable
components. This translates into less time and consequently less cost to develop applications.
ii. Deployment: With features such as no-impact applications, private components, controlled code sharing,
side-by-side versioning and partially trusted code, the .Net Framework makes deployment easier post
development. The code execution environment supports safe code execution for reduced conflicts in
software development and versioning, and minimized performance problems of scripted or interpreted
environments.
iii. Reliability:Since its release in 2002, .NET has been used to develop thousands of applications. Its
performance on different Microsoft operating systems (Client and Server) is also very stable and reliable.
iv. Security: .NET offers enhanced application security as web applications developed using ASP.Net have
Windows confirmation and configuration. Managed code and CLR offer safeguard features such as role-
based security and code access security.
v. Use across platforms and languages: .NET allows developers to develop applications for a desktop, a
browser, a mobile browser or an application running on PDA. .NET is promoted as a language-independent
framework, which implies that development can take place in different compliant languages that include C#,
managed C++, VB.NET, Visual COBOL, IronPython, IronRuby and more.
vi. Use of service-oriented architecture: .NET is often used for Web Services, which are solution for
executing an SOA strategy. Through Web Services, applications which are designed in different
programming languages or platforms, are able to communicate and transmit data utilizing standard Internet
protocols.
vii. Integration with legacy systems: The capability of .NET to process all types of XML documents and
write any format of file with swiftness and ease, provides multiple routes for integration.

In general, using .Net you can develop

 Desktop applications that include: (Windows GUI application or Windows Forms or winforms
applications, Accounting applications, Product/inventory applications, warehousing applications using
hand-held devices, application for value chain/supply management, windows services applications etc)
 Web based applications including: (Web sites, XML web sites, applications requiring integration with
partners through the Internet etc)
 Applications on embedded systems like: (PAD (hand-held) applications, applications for mobiles)
 Others including: Windows Presentation Foundation (WPF) applications. Console based applications,
service-oriented applications using Windows Communication Foundation (WCF), Workflow-enabled
applications using Windows Workflow Foundation (WF)

Event driven programming 4 2023


2.3 Introduction to Microsoft Visual Studio 2012

Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. Itcan be used to develop
console and graphical user interface applications along withWindows Forms applications, web sites, web
applications, and web services.
There exist different versions of Visual Studio, such as Visual Studio Express (free), Visual Studio Professional,
Visual Studio Premium and Visual Studio Ultimate.The Visual Studio product family shares a single integrated
development environment (IDE)that is composed of several elements: the Menu bar, Standard toolbar, various tool
windowsdocked or auto-hidden on the left, bottom, and right sides, as well as the editor space. Thetool windows,
menus, and toolbars available depend on the type of project or file you are working in.
 New projects are created from the “New Project” window:
Below we see the Visual Studio IDE (Integrated Development Environment):

New Project
The first thing you do when you want to create a new application is to create a new project.
This can be done from the Start Page:

Event driven programming 5 2023


Or from the File menu: (FileNewProject…)

Then the “New Project” window appears:

In this window you select an appropriate template based on what kind of application youwant to create, and aname
and location for your project and solution.
The most common applications are:
 Windows Form Application
 Console Application
 WPF Application
 ASP.NET Web Application

Event driven programming 6 2023


 Silverlight Application

Solution Explorer
Solutions and projects contain items that represent the references, data connections,folders, and files that you need
to create your application. A solution container can containmultiple projects and a project container typically
contains multiple items.

Toolbox
The Toolbox contains all the necessary controls, etc. you need to create your user interface.
See Figure below.

The Toolbox contains all the controls, etc. we can use


in our user interface.In order to use them in our user
interface, we just drag and drop them to the “Form”,
as shown below:

Event driven programming 7 2023


Editors and Designers
1. Graphical User Interface Designer:

2. Code Editor:double click the form to go in to the code


Properties window
Each control we have on our user interface
has lots of Properties we can set.

Build and Debug Tools


In Visual Studio we have lots of Build and Debugging Tools.

Event driven programming 8 2023


The most used tool is “Build Solution” (Shortcut Key: F6).
The most used tool is “Start Debugging” (Shortcut Key: F5).

2.3.1 SDI and MDI Forms

A single-document interface, SDI, is an application primarily made of a form equipped with a menu.A multiple-
document interface, MDI, is an application that primarily has a form and a menu. A Multiple Document Interface
(MDI) programs can display multiple child windows inside them. This is in contrast to single document interface
(SDI) applications, which can manipulate only one document at a time. Visual Studio Environment is an example
of Multiple Document Interface (MDI) and notepad is an example of an SDI application. MDI applications often
have a Window menu item with submenus for switching between windows or documents.

SDI MDI

The primary form of an MDI application is referred to as the parent or MDI container. It provides the frame inside
of which the documents will reside. To provide this functionality, the Form class is equipped with a Boolean
property named IsMdiContainer. Therefore, after creating the first form of your application, to indicate that it acts
as the main frame, set this property to true. You can do this in the Properties window or programmatically.The
primary characteristic of an MDI is that it contains other forms. These forms must be created and made available to
the parent. Each form can be created using a predefined form or you can programmatically create one by declaring
an object of type Form. To allow you to specify that a form has a parent and will act as a child, the Form class is
equipped with a property named MdiParent. This is a read-write property. The set accessor indicates what form
acts as this one's parent. To provide this information, assign the main form this form's MdiParent. After doing this,
you can display the form when you are ready, by calling its Show() method.

The following C# program shows a MDI form with two child forms.

Event driven programming 9 2023


namespace WindowsFormsApplication1
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}

privatevoid Form1_Load(object sender, EventArgs e)


{
IsMdiContainer = true;
Form frm2 = newForm2();
frm2.MdiParent = this;
frm2.Text = "Form 2";
frm2.Show();
Form frm3 = newForm3();
frm3.MdiParent = this;
frm3.Text = "Form 3";
frm3.Show();
}
publicstaticint main(){
Application.Run(newForm1());
return 0;
}
}
publicpartialclassForm2 : Form
{
public Form2()
{
}
}
publicpartialclassForm3 : Form
{
public Form3()
{
}
}
}
Further reading assignments

1. Common controls in visual studio 2012


2. Design principles of .Net Framework

Event driven programming 10 2023

You might also like