Created
April 11, 2017 17:34
-
-
Save yallie/fd1105ba98919006d3e93d956f705ef8 to your computer and use it in GitHub Desktop.
Event invocation demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
class Program | |
{ | |
static event EventHandler Handler; | |
static void Main() | |
{ | |
Handler += (s, e) => { Console.WriteLine($"1: {Thread.CurrentThread.ManagedThreadId}"); }; | |
Handler += (s, e) => { Console.WriteLine($"2: {Thread.CurrentThread.ManagedThreadId}"); }; | |
Handler += (s, e) => { Console.WriteLine($"3: {Thread.CurrentThread.ManagedThreadId}"); }; | |
Handler += (s, e) => { Console.WriteLine($"4: {Thread.CurrentThread.ManagedThreadId}"); }; | |
Handler += (s, e) => { Console.WriteLine($"5: {Thread.CurrentThread.ManagedThreadId}"); throw new Exception(); }; | |
Handler += (s, e) => { Console.WriteLine($"6: {Thread.CurrentThread.ManagedThreadId}"); }; | |
Handler(null, EventArgs.Empty); | |
} | |
} | |
// output: | |
// 1: 1 | |
// 2: 1 | |
// 3: 1 | |
// 4: 1 | |
// 5: 1 | |
// Unhandled exception: System.Exception: (...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment