Skip to content

Instantly share code, notes, and snippets.

@alfeg
Created January 25, 2011 12:02
Show Gist options
  • Save alfeg/794834 to your computer and use it in GitHub Desktop.
Save alfeg/794834 to your computer and use it in GitHub Desktop.
class A
{
private object _locker = new object();
public event EventHandler Bang;
public void Foo()
{
new Thread(() =>
{
lock (_locker)
{
if (Bang != null) Bang(this, EventArgs.Empty);
}
}).Start();
Thread.Sleep(10);
lock (_locker)
{
Console.WriteLine("Locked!");
}
}
}
class B
{
static B()
{
var a = new A();
a.Bang += (o, e) => Console.WriteLine("Handled");
a.Foo();
}
}
class Program
{
static void Main(string[] args)
{
B b = new B();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment