HomeGenie Forum

General Category => Troubleshooting and Support => Topic started by: pim555 on February 02, 2015, 09:57:13 PM

Title: Event handling in C#
Post by: pim555 on February 02, 2015, 09:57:13 PM
Hello,

I am having trouble in understanding how events are being handled within HG. I have a piece of code that looks for parameters changing:

When.ModuleParameterIsChanging((module, parameter) => {

What is not clear to me is what exactly happens when you return true or false from within this iteration?

Cheers
Pim
Title: Re: Event handling in C#
Post by: bkenobi on February 02, 2015, 11:54:38 PM
True stops the iteration, false continues on.

If you have several modules that change at the same time and you want to do something when one of them changes, you would want to use false at least until the module you are searching for has been dealt with.  If you want to be complete, you should continue to return false but you could instead return true to kick out at that point too.  Depends on your goal.
Title: Re: Event handling in C#
Post by: Gene on February 03, 2015, 12:05:54 AM
hey bkenobi,

that's not the purpose of the return value for ModuleParameterIsChanging (http://www.homegenie.it/docs/doxy/d4/dd7/class_home_genie_1_1_automation_1_1_scripting_1_1_events_helper.html#a2345d703592c2fe90284b13ce7ac2650) event.
If the return value is true, HG will continue propagating the event to other possible listeners (other programs that are listening to the "parameter is changing" event).
If the return value is false, HG will stop propagating that event (other listeners won't receive it).

Cheers,
g.
Title: Re: Event handling in C#
Post by: bkenobi on February 03, 2015, 03:34:16 AM
Wonder if that caused issues when writing the Advance Smart Lights code.  Doh!   :-[

It's working, so I guess it must not be an issue.
Title: Re: Event handling in C#
Post by: nolio on February 03, 2015, 06:19:40 AM
Gene, I guess it's the same way for ModuleParameterChanged. Is it ?