摘要:
要提高代码的可靠性,就必须实现某种代码隔离层(或者说独立层)。隔离层要确保运行在某个隔离边层内的代码不会对其他隔离层中的代码产生负面影响。 如果不能实现这种保证,那么一些不良行为的代码将很容易破坏其他的应用程序或者整个系统。换句话说,这种隔离层的作用就是提升系统的稳定性与可靠性。 Windows通过进程来实现这种隔离机制。所有的可执行代码、数据,以及其他资源都被包含在进程中,系统中其他进程通常不允许对它们进行访问(除非持有 足够的权限)。同理,.NET应用程序同样是被局限在进程内执行。但是,.NET还进一步引入了另一种逻辑隔离层,称之为应用程序域。在图2-4中给出了 进程与应用域之间的关系。 阅读全文
posted @ 2012-05-14 23:59
ChaunceyHao
阅读(256)
评论(0)
推荐(0)
摘要:
在Windows上运行的应用程序可以通过多种不同的方式来启动。Windows负责处理所有的相关工作,包括设置进程地址空间、加载可执行程序, 以及指示处理器开始执行等。当处理器开始执行程序指令时,它将一直执行下去,直到进程退出。在本章的前面已经讨论过,在.NET应用程序中并不包含机器指 令。因此,在处理器开始执行前,首先需要将中间语言转换为机器指令。尽管存在着这种差异,.NET应用程序仍然可以采取与非托管应用程序一样的启动方式。 为什么这种方式可行?Windows加载器是否知道.NET应用程序的一些特定信息,因此能够自动地启动CLR?答案在于Windows上一种由来已久的 文件格式:可移植的可执 阅读全文
posted @ 2012-05-14 23:57
ChaunceyHao
阅读(234)
评论(0)
推荐(0)
摘要:
分析.NET应用程序启动过程的最佳方式就是观察一个简单的.NET命令行程序。程序的源代码和程序集分别位于以下文件夹中: 源代码文件:C:\\adnd\\chapter1\\MDASample 程序集文件:C:\\adndbin\\01mdasample.exe 如果运行上面的程序,它会成功执行,如清单2-2所示。 清单2-2执行02simple.exe 由于.NET应用程序在执行时要预先加载CLR,那么Windows如何知道加载并初始化CLR?我们可能会做出一种假设:系统开发人员对 Windows加载器进行了改动以识别.NET程序集,并且当检测到.NET程序集时自动启动CLR。尽管这种... 阅读全文
posted @ 2012-05-14 23:57
ChaunceyHao
阅读(372)
评论(0)
推荐(0)
摘要:
using System;namespace AbstractFactoryPattern { // Abstract Factory D-J Miller and Judith Bishop Sept 2007 // Uses generics to simplify the creation of factories interface IFactory<Brand> where Brand : IBrand { IBag CreateBag(); IShoes CreateShoes(); } // Conctete Factories (both in the same o 阅读全文
posted @ 2012-05-14 21:33
ChaunceyHao
阅读(157)
评论(0)
推荐(0)
摘要:
using System; class SingletonPattern { // Singleton Pattern Judith Bishop Nov 2007 // The public property protects the private constructor public class Singleton { // Private constructor Singleton () { } // Nested class for lazy instantiation class SingletonCreator { static SingletonCreator () {... 阅读全文
posted @ 2012-05-14 21:26
ChaunceyHao
阅读(122)
评论(0)
推荐(0)
摘要:
using System; // Singleton PatternJudith Bishop Nov 2007 // Generic version public class Singleton <T> where T : class, new(){ Singleton() { } class SingletonCreator { static SingletonCreator () {} // Private object instantiated with private constructor internal static readonly T instance = ne 阅读全文
posted @ 2012-05-14 21:26
ChaunceyHao
阅读(135)
评论(0)
推荐(0)
摘要:
using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; namespace PrototypePattern { // Prototype Pattern Judith Bishop Dec 2006 // Serialization is used for the deep copy option [Serializable()] public abstract cla... 阅读全文
posted @ 2012-05-14 21:24
ChaunceyHao
阅读(187)
评论(0)
推荐(0)
摘要:
using System; class SingletonPattern { // Singleton Pattern Judith Bishop Dec 2006 // The public property protects the private constructor public sealed class Singleton { // Private Constructor Singleton() { } // Private object instantiated with private constructor static readonly Singleton inst... 阅读全文
posted @ 2012-05-14 21:24
ChaunceyHao
阅读(131)
评论(0)
推荐(0)
摘要:
using System; using System.Collections.Generic; using System.Runtime.Serialization; using PrototypePattern; // Prototype Pattern Judith Bishop Dec 2006 // The AbstractProtoype is represented by the ICloneable interface // Serializable is used for the deep copy option [Serializable()] // Helper cla.. 阅读全文
posted @ 2012-05-14 21:23
ChaunceyHao
阅读(263)
评论(0)
推荐(0)
摘要:
using System; using System.Collections; class FactoryPattern { // Factory Method Pattern Judith Bishop 2006 // Example of exporting from different suppliers interface IProduct { string ShipFrom(); } class ProductA : IProduct { public String ShipFrom () { return " from South Africa"; } } cl 阅读全文
posted @ 2012-05-14 21:11
ChaunceyHao
阅读(119)
评论(0)
推荐(0)
摘要:
using System; using System.Collections.Generic; using System.IO; using PrototypePattern; namespace CompositePattern { // The Interface public interface IComponent <T> { void Add(IComponent <T> c); IComponent <T> Remove(T s); string Display(int depth); IComponent <T> Find(T s) 阅读全文
posted @ 2012-05-14 21:07
ChaunceyHao
阅读(183)
评论(0)
推荐(0)
摘要:
using System; // Facade Pattern Judith Bishop Dec 2006 // Sets up a library of three systems, accessed through a // Facade of two operations // Compile with csc /t:library /out:FacadeLib.dll Facade2.cs namespace FacadeLib { internal class SubsystemA { internal string A1() { return "Subsystem A, 阅读全文
posted @ 2012-05-14 20:39
ChaunceyHao
阅读(127)
评论(0)
推荐(0)
摘要:
using System; using FacadeLib; // Compile with csc /r:FacadeLib.dll Facade2Main.cs class FacadePattern1 { class Client { public void ClientMain () { Facade.Operation1(); Facade.Operation2(); } } static void Main() { new Client().ClientMain(); }} /* Output:Operation 1Subsystem A, Method A1Subsyste... 阅读全文
posted @ 2012-05-14 20:35
ChaunceyHao
阅读(163)
评论(0)
推荐(0)
摘要:
using System; using EngineeringService; // Two-way Adapter Pattern Pierre-Henri Kuate and Judith Bishop Aug 2007 // Embedded system for a SeaBird flying plane namespace EngineeringService { //ITarget interface public interface IAircraft { bool Airborne {get;} void TakeOff(); int Height {get;} }... 阅读全文
posted @ 2012-05-14 20:34
ChaunceyHao
阅读(171)
评论(0)
推荐(0)
摘要:
using System; // Adapter Pattern - Simple Judith Bishop Aug 2006 // Simplest adapter using interfaces and inheritance // Existing way requests are implemented class Adaptee { // Provide full precision public double SpecificRequest (double a, double b) { return a/b; } } // Required standard for ... 阅读全文
posted @ 2012-05-14 20:33
ChaunceyHao
阅读(157)
评论(0)
推荐(0)
摘要:
using System; // Adapter Pattern - Pluggable Judith Bishop Aug 2006 // Adapter can accept any number of pluggable adaptees and targets // and route the requests via a delegate, in some cases using the // anonymous delegate construct // Existing way requests are implemented class Adaptee { public... 阅读全文
posted @ 2012-05-14 20:32
ChaunceyHao
阅读(169)
评论(0)
推荐(0)
摘要:
using System;namespace Wrox.ProCSharp.Basics{ public enum TimeOfDay { Morning = 0, Afternoon = 1, Evening = 2 } class EnumExample { public static int Main() { WriteGreeting(TimeOfDay.Morning); return 0; } static void WriteGreeting(TimeOfDay timeOfDay) { switch(timeOfDay) { case TimeOfDa... 阅读全文
posted @ 2012-05-14 15:58
ChaunceyHao
阅读(106)
评论(0)
推荐(0)
摘要:
using System;namespace Wrox.ProCSharp.Basics{ class MainEntryPoint { static void Main(string[] args) { Console.WriteLine("Type in a string"); string input; input = Console.ReadLine(); if (input == "") { Console.WriteLine("You typed in an empty string"); } else if (input 阅读全文
posted @ 2012-05-14 15:48
ChaunceyHao
阅读(131)
评论(0)
推荐(0)
摘要:
using System;using Microsoft.Web.Administration;class Program{ static void Main(string[] args) { ServerManager mgr = new ServerManager(); ApplicationPool myAppPool = mgr.ApplicationPools.Add("MyAppPool"); myAppPool.AutoStart = true; myAppPool.Cpu.Action = ProcessorAction.KillW3wp; myAppPoo 阅读全文
posted @ 2012-05-14 15:46
ChaunceyHao
阅读(127)
评论(0)
推荐(0)
摘要:
// Title: Building ASP.NET Server Controls//// Chapter: 5 - Event-based Programming// File: PageCommand.cs// Written by: Dale Michalk and Rob Cameron//// Copyright ?2003, Apress L.P.using System;namespace ControlsBookLib.Ch05{ public enum PageDirection { Left = 0, Right = 1 } public delegate void Pa 阅读全文
posted @ 2012-05-14 00:33
ChaunceyHao
阅读(134)
评论(0)
推荐(0)
浙公网安备 33010602011771号