Csharp/C Sharp by API/System.Threading/Context

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

Context.ContextID

 
using System;
using System.Runtime.Remoting.Contexts;
using System.Threading;
[Synchronization]
public class SynchContextClass : ContextBoundObject
{
  public SynchContextClass()
  {
    Context ctx = Thread.CurrentContext;
    Console.WriteLine("Info about context {0}", ctx.ContextID);
    foreach(IContextProperty itfCtxProp in ctx.ContextProperties)
      Console.WriteLine("-> Ctx Prop: {0}", itfCtxProp.Name);
  }
}
class MainClass
{
  static void Main(string[] args)
  {
    SynchContextClass synchObj = new SynchContextClass();
  }
}


Context.ContextProperties

 
using System;
using System.Runtime.Remoting.Contexts;
using System.Threading;
class MainClass
{
  static void Main(string[] args)
  {
    Context ctx = Thread.CurrentContext;
    Console.WriteLine("Info about context {0}", ctx.ContextID);
    foreach(IContextProperty itfCtxProp in ctx.ContextProperties)
      Console.WriteLine("-> Ctx Prop: {0}", itfCtxProp.Name);
  }
}