Skip to content

Instantly share code, notes, and snippets.

@wsky
Created February 13, 2012 08:32
Show Gist options
  • Save wsky/1815043 to your computer and use it in GitHub Desktop.
Save wsky/1815043 to your computer and use it in GitHub Desktop.
clr event
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var f = new EventFactory();
f.Raised += (o, e) => { Thread.Sleep(100); Trace.WriteLine(1, Thread.CurrentThread.Name); };
f.Raised += (o, e) => { Thread.Sleep(200); Trace.WriteLine(2, Thread.CurrentThread.Name); };
f.Raised += (o, e) => { Thread.Sleep(300); Trace.WriteLine(3, Thread.CurrentThread.Name); };
f.Raised += (o, e) => { Thread.Sleep(400); Trace.WriteLine(4, Thread.CurrentThread.Name); };
f.Raised += (o, e) => { Thread.Sleep(500); Trace.WriteLine(5, Thread.CurrentThread.Name); };
Trace.WriteLine("begin", Thread.CurrentThread.Name);
f.Raise();
Trace.WriteLine("end", Thread.CurrentThread.Name);
}
//public delegate void EventHandler(EventArgs args);
public class EventFactory
{
public event EventHandler Raised;
public void Raise()
{
this.Raised(this, new EventArgs());
}
}
}
@wsky
Copy link
Author

wsky commented Feb 13, 2012

TestRunnerThread: begin
TestRunnerThread: 1
TestRunnerThread: 2
TestRunnerThread: 3
TestRunnerThread: 4
TestRunnerThread: 5
TestRunnerThread: end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment