Duplicate event subscription

9 views
Skip to first unread message

Andrei

unread,
Mar 30, 2011, 9:50:12 AM3/30/11
to SSharp
Hi Petro,

It seems like I can't add two event handlers to the same event

function OnClick1(s,e)
{
MessageBox.Show('Hello1');
}

function OnClick2(s,e)
{
MessageBox.Show('Hello2');
}

Button1.Click += OnClick1;
Button1.Click += OnClick2;

This generates an exception "Duplicate event subscription is not
supported"

Any idea how to make it work?

Thanks!

piter....@gmail.com

unread,
Mar 30, 2011, 2:29:22 PM3/30/11
to SSharp
As stated in exception, duplicate event subscription is not possible
at the moment. I will investigate if that could be fixed.
In the meantime you can combine handlers into a single function:

function AllHandlers(s,e)
{
OnClick1(s,e);
OnClick2(s,e);

Andrei

unread,
Mar 31, 2011, 7:55:54 AM3/31/11
to SSharp
In my scenario it's not easily possible to combine them.
The only option I can see is a service by which I can add\remove
handlers in S#, something like

AddHandler(elem, eventName, onClick1);

such that adding\removing handlers is centralized and there is
actually a single subscription to the event handler.

This needs to be implemented in C# code where I keep an array of all
the handlers for that element and that event.
Also I need to see how to make the syntax to look pretty, because
writing the event name as a string is not.

Not sure if even all this possible.
What do you think?

Thanks!

On Mar 30, 9:29 pm, "Piter.Prot...@gmail.com"

piter....@gmail.com

unread,
Apr 5, 2011, 2:09:22 PM4/5/11
to SSharp
I have implemented support for multiple event subscriptions, see
issue:
https://github.com/PetroProtsyk/SSharp/issues/closed#issue/13

Andrei Nitescu

unread,
Apr 6, 2011, 12:51:13 PM4/6/11
to ssh...@googlegroups.com
That is great. Thank you.
Reply all
Reply to author
Forward
0 new messages