C# events examined

I recently ran into a threading bug involving adding handlers to events, and decided to take a deeper look at the compiler-generated event accessors. Suppose you create a class like this one:using System; class C { public event EventHandler E; public void AddHandler() { E += Handler; // thread-safe? } public void Handler(object sender, EventArgs…


C# Warning CS0067: The event ‘event’ is never used

Suppose you’re implementing an interface like the following, which contains some events you care about and some you don’t:public interface I { event EventHandler Important; event EventHandler Unimportant; } Forgetting about “unimportant” details, you’d probably start your implementation like this:public class C : I {     public event EventHandler Important;       protected virtual void OnImportant(EventArgs…



The purpose of this blog is simply to record and share little programming ideas, tips, and tricks that I run across. Don’t count on being awed by earth-shattering insights, but hopefully you’ll find something here that saves you time or headaches. 🙂 -Trevor Robinson