Application Domains

A process is, essentially, a running application. Each .NET application runs in its own process. If you have Word, Excel, and Visual Studio open, you have three processes running. If you open another copy of Word, another process starts up. Each process is subdivided into one or more application domains (or app domains). An app domain acts like a process but uses fewer resources. App domains can be independently started and halted they are secure, lightweight, and versatile. An app domain can...

The End of DLL Hell

You will remember this scenario you install Application A on your machine, and it loads a number of DLLs into your Windows directory. It works great for months. You then install Application B on your machine, and suddenly, unexpectedly, Application A breaks. Application B is in no way related to Application A. So what happened It turns out, you later learn, that Application B replaced a DLL that Application A needed, and suddenly Application A begins to...

Explicit Interface Implementation

In the implementation shown so far, the implementing class (in this case, Document) creates a member method with the same signature and return type as the method detailed in the interface. It is not necessary to explicitly state that this is an implementation of an interface this is understood by the compiler implicitly. What happens, however, if the class implements two interfaces, each of which has a method with the same signature Example 8-5 creates two interfaces IStorable and ITalk. The...

Example 116 Working with an exception object

Test t new Test( ) t.TestFunc( ) try to divide two numbers handle possible exceptions Console.WriteLine(Open file here) double a 12 double b 0 Console.WriteLine ( 0 1 2 , a, b, DoDivide(a,b)) Console.WriteLine ( This line may or may not print) most derived exception type first catch (System.DivideByZeroException e) nDivideByZeroException Msg 0 , e.Message) nHelpLink 0 , e.HelpLink) nHere's a stack trace 0 n, e.StackTrace) Unknown exception caught) Console.WriteLine ( Close file here.) public...

Dynamic Invocation with Invoke Member

The first approach will be to create a class named BruteForceSums dynamically, at runtime. The BruteForceSums class will contain a method, ComputeSum , that implements the brute-force approach. You'll write that class to disk, compile it, and then use dynamic invocation to invoke its brute-force method by means of the InvokeMember method of the Type class. The key point is that BruteForceSums.cs won't exist until you run the program. You'll create it when you need it and supply its arguments...

Example 2110 Implementing an asynchronous network streaming server

Public ClientHandler Socket socketForClient socket socketForClient buffer new byte 256 networkStream new AsyncCallback this.OnReadComplete new begin reading the string from the client buffer, 0, buffer.Length, callbackRead, null when called back by the read, display the string and echo it back to the client private void OnReadComplete IAsyncResult ar int bytesRead networkStream.EndRead ar buffer, 0, bytesRead Console.Write Received 0 bytes from client 1 , bytesRead, s networkStream.BeginWrite...