If you can use Reactive Extensions for.NET , you can simplify this.
You can make an Observable from an event and listen only to the first element with .Take(1) to make your own small piece of code. This turns this whole process into a couple of lines of code.
Edit: To demonstrate, I made a complete sample program (I will embed below).
I moved the observed creation and subscription to the method ( HandleOneShot ). This allows you to do what you are trying with a single method call. For demonstration, I created a class with two properties that implements INotifyPropertyChanged, and I listen to the event with the first property changed, writing it to the console when this happens.
This takes your code and changes it to:
HandleOneShot<SomeEventArgs>(variableOfSomeType, "SomeEvent", e => {
Please note that all subscription / unsubscribing is done automatically for you backstage. There is no need to process the subscription manually - just subscribe to the Observable and Rx will take care of this for you.
When launched, this code prints:
Setup... Setting first property... **** Prop2 Changed! /new val Setting second property... Setting first property again. Press ENTER to continue...
You receive only one trigger of your event.
namespace ConsoleApplication1 { using System; using System.ComponentModel; using System.Linq; class Test : INotifyPropertyChanged { private string prop2; private string prop; public string Prop { get { return prop; } set { if (prop != value) { prop = value; if (PropertyChanged!=null) PropertyChanged(this, new PropertyChangedEventArgs("Prop")); } } } public string Prop2 { get { return prop2; } set { if (prop2 != value) { prop2 = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Prop2")); } } } public event PropertyChangedEventHandler PropertyChanged; } class Program { static void HandleOneShot<TEventArgs>(object target, string eventName, Action<TEventArgs> action) where TEventArgs : EventArgs { var obsEvent = Observable.FromEvent<TEventArgs>(target, eventName).Take(1); obsEvent.Subscribe(a => action(a.EventArgs)); } static void Main(string[] args) { Test test = new Test(); Console.WriteLine("Setup..."); HandleOneShot<PropertyChangedEventArgs>( test, "PropertyChanged", e => { Console.WriteLine(" **** {0} Changed! {1}/{2}!", e.PropertyName, test.Prop, test.Prop2); }); Console.WriteLine("Setting first property..."); test.Prop2 = "new value"; Console.WriteLine("Setting second property..."); test.Prop = "second value"; Console.WriteLine("Setting first property again..."); test.Prop2 = "other value"; Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); } } }