The above code contains simple blocks, a block called DispatchEvent() that calls MyEvent("hello world"). This is expected to work correctly, but the following behaviour happens:
When DispatchEvent() block is called from Initialize event block, EventDispatcher.dispatchEvent() returns false.
When DispatchEvent() block is called on an event of a Button click, the event gets dispatched successfully.
This is by design. No events can be dispatched until the screen finishes initializing and its Initialize event runs. If you have events you need to dispatch, you should defer them until after initialization of the screen has completed.
One might expect special design rules to apply to processing done from within Screen1.initialize. Inference from the following topic, suggests that at least some events cannot be scheduled/queued from initialize execution.
I suspect the following simple app, init_sandbox, illustrates such a case having to do with events being "scheduled" or "queued" during Screen1.Initialize execution.
Once the app in installed, the phone settings is used to enable permissions for CAMERA and CONTACT.
When the init_sandbox app starts, Screen1.Initialize requests permission for CAMERA and CONTACT access. But neither the PermissionGranted nor the PermissionDenied event is execute.
When the Re-initialze button is pressed, the same permissions are requested and both are granted giving rise to the execution of the PermissionGranted event for both of them.