Tuesday, July 13, 2010

Synchronization Contexts

Synchronization Contexts provide a mechanism to lock declaratively/Automatically.

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

[Synchronization]
public class MyLock:ContextBoundObject
{
public void DoSomething()
{
//do something....
}
}

public class MyTestClass
{
public static void Main()
{
MyLock instance=new MyLock();
new Thread(instance.DoSomething).Start();
new Thread(instance.DoSomething).Start();
instance.DoSomething();
}
}

No comments: