Context Manipulator : Current Thread « Thread « C# / CSharp Tutorial






using System;
using System.Runtime.Remoting.Contexts;
using System.Threading;

  public class MyClass
  {
    public MyClass()
    {
      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);
    }
  }
  public class MyClassTS : ContextBoundObject
  {
    public MyClassTS()
    {
      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)
    {
            MyClass sport = new MyClass();
            MyClass sport2 = new MyClass();
            MyClassTS synchroSport = new MyClassTS();
        }
  }








20.11.Current Thread
20.11.1.CurrentThread: Name, ApartmentState, IsAlive, Priority, ThreadState
20.11.2.Current Thread HashCode
20.11.3.Context Manipulator