Without a doubt, Windows Runtime is the
key component in the Windows 8 style application architecture. It
represents a big leap in the evolution of the programming model,
similar to what the .NET Framework did in 2002. The Microsoft team
responsible for this great architectural piece describes Windows
Runtime as “the solid, efficient foundation for building great Windows
8 style apps.”
The language run
times utilized before .NET provide libraries that conceal most of the
API operations, and expose a simpler set of objects and functions to
make common programming tasks easier. The .NET Framework adds a runtime
environment to these objects with extra features like garbage
collection, exception handling, communication support between
applications, and much more.
Although language runtime libraries and the .NET
Framework have been continuously evolving for a long time, they still
do not expose all data structures and operations proffered by the Win32
API. The main reason for this plight is that the runtime components
utilizing Win32 are created separately from the services of the
operating system.
This situation totally changed with Windows 8.
Windows Runtime is an organic part of the operating system. It is not
an additional component to be installed separately, such as the Windows
Software Development Kit (Windows SDK). Every time a new Windows 8
build is created, the APIs and Windows Runtime are built together with
the other parts of the operating system. Let’s take a closer look at
the power of this great new component.
1. Windows Runtime Architecture Overview
Just as Windows 8 was designed with the
user experience in mind, Windows Runtime was designed with a focus on
the developer experience. Modern development environments such as
Visual Studio provide great tooling to make
developers more productive.
Windows Runtime Design Principles
A good example of a productive tool is
IntelliSense, which watches the context as you are typing the code, and
automatically offers a list of possible continuations. As shown the
example in Figure 1, IntelliSense provides a list of expressions that may follow the this member in the context of the MainPage
method. IntelliSense not only displays the list of appropriate members,
but it also displays a short explanation of the selected member (AllowDrop)
in a tooltip. The team responsible for the design of Windows Runtime
continuously kept in mind that the new API should be very easy to use
with powerful tools like IntelliSense.
The smooth user experience of Windows 8 can be
delivered only by applications that keep the UI responsive. In the
past, the biggest issues with Windows were bound to the lazy and rugged
behavior of the operating system and its applications. For example, the
user started to drag an object on the screen by moving the mouse
fluently, but the object moved in a “bitty” fashion.
The asynchronous programming model provides a
great remedy for this kind of issue. The model does not block the UI
while performing long or resource-intensive computations in the
background. The APIs of Windows Runtime were established with
asynchrony in the mind. The design team made a tough decision: All operations that may take more than 50 milliseconds are implemented as asynchronous operations.
The new versions of the C# and Visual Basic programming languages
shipped with Visual Studio 2012 and support this programming model.
The Windows team has always invested a lot in
providing backward application compatibility with every new Windows
release. Windows Runtime is designed and established so that
applications keep running in new Windows versions. If an API changes an
operation in a new version of the operating system, the older operation
versions still remain available in parallel with the new one, so they
can be used side-by-side. Each application uses the version of the
operation with which it was created.
The Building Blocks of Windows Runtime
Reflective of Microsoft’s design
principles, Windows Runtime is not simply a set of APIs. It is a real
runtime environment that binds the operating system services with the
Windows 8 style applications built on them, independently of the
programming language used to implement a particular application. This
runtime environment is composed from several building blocks, as shown
in Figure 2.
Windows OS are exposed to Windows 8 style
applications through the Windows Runtime core block, which (as its name
suggests) is the essence of the runtime environment. This core block
wraps the low-level services into types and interfaces. On top of the
core are many APIs, each of which is responsible for a certain kind of
common operating system task. Although in Figure 2 only a few of them are shown, more than two dozen APIs are available.
You do not have to remember each type, interface,
or even the API in which a certain type or functionality can be found,
because Windows Runtime has its own metadata describing information
about them. Moreover, the elemental types are grouped into hierarchical
namespaces — such as objects in the .NET Framework, or in the Java
Runtime — so it is quite easy to find them.
NOTE You learn more about Windows Runtime shortly.
Programming languages have different
characteristics, and they use disparate conventions. At the top of the
APIs and the metadata block, there is a thin layer, Language
Projection, which is responsible for exposing the APIs in a
language-specific way. Windows 8 style applications access Windows
Runtime APIs through this layer.
A few other components shown in Figure 2
complete the environment where Windows 8 style applications can fully
exploit the capabilities of the operating system through Windows
Runtime:
- Your application might access specific system resources (such as
the webcam, the microphone, or the Internet) where the user’s
permission is required. These resources can be accessed only through
the Runtime Broker component that asks the user whether he or she
allows the access to the resource — the first time an operation tries
to use it. For example, if you create an application that picks up the
user’s photo from the webcam, Runtime Broker does not let the system
capture the photo unless the user explicitly enables it.
- As you already learned, you can use HTML5 and JavaScript to create
Windows 8 style applications. These apps — because of their web nature
— run in a web host.
- Each language has some specific runtime support (for example, runtime libraries that support the language, such as the printf C++ function, or append JavaScript method, or the String.Split
operation available from C# and Visual Basic). These can be found in
the Language Support building block that cooperates with the Language
Projection layer.
Some of the building blocks shown in Figure 2 play an important role in everyday programming activities. In the next few sections, you learn more details about them.