In doing some debugging, I’ve just discovered something that I had not realized until today (maybe I should have but I had not)…
It appears that raising an event that does not return a value, creates a whole new stack. Meaning, you make the call to raise the event and your current method continues on after that. The event the takes place some times later. I always thought that order execution would be the call, the event method and then the code after the event call.
The StartingUp property gets set PRIOR to the ContainerInitializedLoadData event taking place. If I were to make that event a function that returns a value, then that would force the election to happen in order. But without that, it appears that raised events just take place “some time” after they are raised.
Is this correct behavior (I assume it is by design in Xojo)? Am I seeing this correctly too?
Desktop. The event is raised on the same thread (main). It’s just happening at some other point in time. It is not following sequentially.
I discovered it because there are some things in that event method that should only execute if the value of StartingUp is false, but yet they were happening. So I started adding break points to see what was going on. The breakpoint for “StartingUp = False” above was happening before the breakpoint in the event method.
The code I posted is in a container control that gets embedded in a Window. The handler method for the event is in that Window. That’s in the AddHandler directive.
Should I be adding the handler from the containing Wu doe instead of the ContainerControl?
[quote=319099:@Jon Ogden]The code I posted is in a container control that gets embedded in a Window. The handler method for the event is in that Window. That’s in the AddHandler directive.
Should I be adding the handler from the containing Wu doe instead of the ContainerControl?[/quote]
Right, but WHERE in the container? Constructor? An event?
If I make the Open event of the container as such:
Sub Open() Handles Open
AddHandler me.ContainerInitializedLoadData, AddressOf VWCWin.LoadDataIntoContainer
AddHandler me.APICommandProcessed, AddressOf VWCWin.CandC_APICommandProcessed
Dim b as Boolean = RaiseEvent ContainerInitializedLoadData(ContainerIndex)
StartingUp = False
End Sub
The Event still fires AFTER the open event completes. I’m wondering if I just can’t Raise and event from inside the open event of the container.
And further contributing to my confusion…
In the handler method for the event, I forced “Return True” so that the boolean variable b above would be true if the event executed. So in the debugger, b is true even though the breakpoint I have in the event code has not happened yet! So that I don’t understand either…
OK. Never mind. My breakpoint in the handler method was not being seen as it was inside an If block that wouldn’t execute if StartingUp is True. So it’s morning and I’ve not had enough coffee. My bad.