Skip to content

Instantly share code, notes, and snippets.

@lauromoura
Last active August 15, 2018 01:01
Show Gist options
  • Save lauromoura/6c80174a42e59fd5aeb367c1a67d6560 to your computer and use it in GitHub Desktop.
Save lauromoura/6c80174a42e59fd5aeb367c1a67d6560 to your computer and use it in GitHub Desktop.
using System;
public class CustomEvent
{
object eventLock = new Object();
public event EventHandler CustomEvt
{
add
{
lock (eventLock)
{
Console.WriteLine("Add called");
CustomEvt += value;
}
}
remove
{
lock (eventLock)
{
Console.WriteLine("Remove vcalled");
CustomEvt -= value;
}
}
}
public event EventHandler PlainEvt;
public void OnCustomEvt(EventArgs e)
{
// Breaks with error CS0079: The event "CustomEvent.ChangedEvt" can only appear on the left hand side of "+=" or "-=" operator
CustomEvt(this, e);
}
public void OnPlainEvt(EventArgs e)
{
PlainEvt(this, e);
}
public static void Main()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment