Csharp/CSharp Tutorial/Development/ContextProperty

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Context Manipulator

using System;
using System.Runtime.Remoting.Contexts;
using System.Threading;
public class SportsCar {
    public SportsCar() {
        Context ctx = Thread.CurrentContext;
        Console.WriteLine("{0} object in context {1}", this.ToString(), ctx.ContextID);
        foreach (IContextProperty itfCtxProp in ctx.ContextProperties)
            Console.WriteLine("-> Ctx Prop: {0}", itfCtxProp.Name);
    }
}
[Synchronization]
public class SportsCarTS : ContextBoundObject {
    public SportsCarTS() {
        Context ctx = Thread.CurrentContext;
        Console.WriteLine("{0} object in context {1}", this.ToString(), ctx.ContextID);
        foreach (IContextProperty itfCtxProp in ctx.ContextProperties)
            Console.WriteLine("-> Ctx Prop: {0}", itfCtxProp.Name);
    }
}

class Program {
    static void Main(string[] args) {
        SportsCar sport = new SportsCar();
        Console.WriteLine();
        SportsCar sport2 = new SportsCar();
        Console.WriteLine();
        SportsCarTS synchroSport = new SportsCarTS();
        Console.ReadLine();
    }
}