Click here to Skip to main content
15,877,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So I am able to subscribe to a single event and perform functions on that one event.

However, I want to be able to generalize the idea to multiple different events. For example, instead of "gulfstream" I want to be able to do this on "boeing747" and other known stuff for which I want to perform the same or different operations.

Is there any advice on how to do this? The syntax for the event stuff is a little weird so I am not sure how this would be implemented in classes, for example. Would classes be the way to go and instantiate objects that subscribe to and use the events separately? Examples would be very welcome.

What I have tried:

<pre>   socket.eventPool.Subscribe("flight", new EventHandler<flightArgs>((x, y) => Console.WriteLine(y.STR1.temp + " " + y.STR1.alt)));
Updated 18-Aug-21 21:51pm

1 solution

Events have two parameters: an object called sender and an EventArgs called e

The first one of these is the class instance that raised the event: for a Form.Load event that would be the form instance that is about to be displayed. For a Button.Click event, that would be the Button the user pressed.

The x in the code you found online is the sender, the y is the EventArgs - so the x provides you with information on the class that raised it. Use the debugger to find out what is in x, and you can work back from there to the type you need to identify the plane.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900