.NET Framework Info

Array Collections File String Windows VB.NET Algorithm ASP.NET Cast Class Compression Convert Data Delegate Directive Enum Exception If Interface Keyword LINQ Loop Method .NET Number Regex Sort StringBuilder Struct Switch Time Value

.NET Framework

In 2002 the .NET Framework was released. With it came the C# and VB.NET languages. These languages access types from the .NET Framework. Compilers translate these languages into intermediate representations. The virtual execution engine then runs. It optimizes and executes instructions.

Compiler Explanation Console Programs Drawing Instructions Intermediate Language Reflection Thread Overview Visual Studio Tips

The .NET applications generated by .NET-oriented compilers are represented in an abstract, intermediate form, independent of the original programming language and of the target machine and its operating system. Lidin, p. 4

Environment

.NET Framework information

The Environment type exposes many useful pieces of functionality for your C# programs in the .NET Framework. To start, this short program shows how you can use the Environment type. It includes the System namespace. It then accesses and prints the ProcessorCount integer from the Environment class.

Program that uses Environment type [C#]

using System;

class Program
{
    static void Main()
    {
	// Test Environment type.
	Console.WriteLine(Environment.ProcessorCount);
    }
}

Output
    (Depends on the machine.)

2

Overview: These C# articles explore the .NET Framework and many of its types.

Method call

Methods. Here we look at specific methods of the Environment type. These methods are public static methods, which means you call them with the syntax Environment.ExpandEnvironmentVariables() or whatever method name you want.

Environment ExpandEnvironmentVariables Environment GetCommandLineArgs Environment GetLogicalDrives Environment ProcessorCount Environment.Exit Method Environment.GetFolderPath Environment.NewLine Environment.SpecialFolder

GetCommandLineArgs: You can access the command line arguments to a program anywhere with the Environment.GetCommandLineArgs method.

Exit: The Environment.Exit method does not involve exception handling. Instead, it completely bypasses it. A finally block is never executed after an Environment.Exit call.

SpecialFolder: Sometimes, you need to get the location of a special folder on the Windows computer the program is running on—the SpecialFolder enum type is perfect for that.

Process

Process illustration

The Process type represents an operating-system level process. You can command the operating system to start and kill a process, and provide arguments to it at startup. This simple program demonstrates how you can use an instance of the Process class. The GetCurrentProcess returns a reference to the Process object associated with the currently executing program.

Process.Start

Computational processes are abstract beings that inhabit computers. Abelson & Sussman, p. 1

Program that uses Process type [C#]

using System;
using System.Diagnostics;

class Program
{
    static void Main()
    {
	Process process = Process.GetCurrentProcess();
	Console.WriteLine(process.ProcessName);
    }
}

Output

ConsoleApplication1

Get processes. You can get an array of the processes currently running on the computer. This can be useful for certain kind of diagnostics programs, and some examples of this are revealed.

Process.GetProcesses Process.GetProcessesByNameArrow indicates movement

Redirect output. Sometimes, you may want to redirect the output of a process you call externally. You can redirect the output to the same program you called it from. The article linked here describes how you can accomplish this.

RedirectStandardOutput

Kill processes. This is probably the most violent article on this website currently. It describes how you can actually kill processes. This is done with the Kill instance method. Parental guidance is advised.

Kill

Memory

Garbage collection visualization

The .NET Framework provides a garbage-collected heap for the C# programming language, but this does not negate the benefits of careful observation and optimizations of memory usage in C# programs. Many programs written in C# have memory problems. You must be careful to unroot references to objects, so the GC can release them.

The performance of a system is often limited not by the speed of the processor but by the performance of the memory subsystem. Aho et al., p. 20
We could think of the entire computer memory as an array, with the memory addresses corresponding to array indices. Sedgewick, p. 83

Program that determines memory usage [C#]

using System;

class Program
{
    static void Main()
    {
	long memory = GC.GetTotalMemory(false);
	Console.WriteLine("Bytes used: {0}", memory);
    }
}

Output
    (May vary based on your system.)

Bytes used: 53856
Garbage collection (GC)

GC methods. You can influence the garbage collector in your C# program by using the methods on the GC type. We provide examples for using the GC.Collect method, and also the GC.GetTotalMemory method.

GC.Collect Use GC.CollectionCount Example GC.GetTotalMemory Usage

Garbage collection overview. The C# language is garbage-collected. You never need to specify that memory should be reclaimed by the system. We reveal some characteristics of garbage collection, providing visual graphs of garbage collections in action.

Garbage Collection Performance Garbage Collection VisualizationsQuestion and answer

Type instances. How much memory do certain types use? These articles investigate. They reveal how much memory is used by decimal types, nullable types, strings, and reference and value types in general.

Decimal Memory Nullable Memory String Memory Memory UsageArray type

Measure arrays. How much memory do arrays use in the C# programming language and .NET Framework? These articles attempt to answer this question, providing benchmarks of arrays against other types.

Array Memory Bool Array Memory

WeakReference. We provide an example for the WeakReference type in the .NET Framework. This type influences the behavior of the garbage collector, and enables you to implement certain caching behaviors.

WeakReferenceUsing keyword

Dispose. The using statement in the C# language is an excellent way to ensure memory is released as soon as possible. It invokes the Dispose method in the underlying implementation.

Using Using Performance

Memory hierarchy. Here we reference a popular compiler textbook. One of the most important things to know about software performance is how different levels in the level memory hierarchy vary in access times.

Memory Hierarchy Temporal Locality Locality of Reference

System namespace

Many of the most common types in the .NET Framework are located in the System namespace. You can find more about these types in this description.

Using System

Performance

Performance optimization

I think performance is important. One of the best things about the developers behind the .NET Framework is that they do too. Microsoft's teams are very careful to maintain good performance or improve performance where it may be lacking. I benchmarked the .NET Framework 4.0 and found an overall improvement over .NET 3.5 SP1.

Performance Benchmark

Summary

The C# programming language

The .NET Framework includes the infrastructure upon which the C# language and VB.NET language can be written and compiled. It additionally provides the runtime that executes those compiled programs. Because of this, understanding the .NET Framework is equally important as understanding the language you are writing code in.

Dot Net Perls