How to handle C# events

I imported a class from a library that defines an event source:

    class Client {
        public event EventHandler<Group> GroupDiscovered;
    }

If I want to use this, in C# I can just do

    class Program
    {
        static void Main(string[] args)
        {
            Client client = new Client();
            client.GroupDiscovered += GroupDiscovered;
        }

        static void GroupDiscovered(object sender, Group group)
        {
            Console.WriteLine($"{group.id} {group.Name}");
        }
    }

What’s the equivalent of this in VL? If I create a GroupDiscovered node and feed it a Client, I get Observable<EventHandler2<Group>> on the output. My questions:

  • How do I create a function (a node?) that will be invoked when the event fires? Does this have anything to do with Delegates maybe?
  • How to I attach it to the event source? As far as I understand, the GroupDiscovered node will allow me to retrieve the attached handlers from a Client instance, but how do I add a new one?
1 Like

this documentation needs to be updated/improved, but you should get the gist of it: https://thegraybook.vvvv.org/reference/extending/writing-nodes.html#eventsobservables

what’s not obvious is that EventHandler2 is a descendent of EventHandler and the Eventargs property is defined in EventHandler, not EventHandler2.

let us know if this needs further clarification.

Thanks @joreg. I don’t know how I missed that chapter of the docs. This is actually more straightforward than C#.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.