© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
21 replies
The Orange Tea Frog

✅ How can I get multiple responses from raising an event?

Typically, when you raise an event you don't expect a response. However, you can define you own delegate that has a non-void return type which will mean that a subscriber can return a value. Alternatively, you can pass a mutable object in the
EventArgs
EventArgs
which the subscriber can change and then that change can be seen by the publisher.

I want to extend this to the case where there are multiple subscribers. The first option doesn't work since you only get the return value of the last subscriber to execute. You can put a
List
List
in the
EventArgs
EventArgs
and then have the subscribers add their responses to it, however, I don't see any way of doing this that would ensure that each of the subscribers cannot see the responses of other subscribers while allowing the publisher to see all of the responses. The best I have come up with is to have the
EventArgs
EventArgs
be readable once (e.g. raising an exception or setting a flag if it is tried to be read more than once) which would allow the publisher to see if any of the subscribers have been looking at the other responses. Is there a better way of doing this?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ my delegate event is not raising the event
C#CC# / help
4y ago
❔ multiple Async responses
C#CC# / help
3y ago
✅ Get delegate from event
C#CC# / help
3y ago
How do i handle an event
C#CC# / help
2y ago