How to wait on a message box


when waiting for an input from the msgbox, what is the best approach?
I need to ask the user for a decision if a certain condition happened and according to his input.
the program would decide on which route it should go.


I have used a while(msg_flag);
but it is pretty ugly. :thinking:


and it doesn’t work also.
I thought it worked but it didn’t.
the msgbox won’t appear on the screen and the program halts on the while loop.

how do you think I should approach this problem?

The best approach is to not wait for it, and to instead trigger whatever you need to do inside an event handler.

How would I just transfer the logic magically there?

In other libraries working with msgbox is more straight forward as they are sequential parts and you get the output as a return.
But here it isn’t that simple.
Using handlers all the time needs more careful design.
Or you will end up with all of your data being global.

And even that won’t help here.
msgboxs are an exception for an on going process.
Inside a loop maybe as in my case here.
So would I complete a loop at the msgbox event?
No, I have to wait for its output. :frowning_face:

I think synchronisation using semaphores -a cleaner solution but still the same to what I did- but they are not implemented in the VS simulation.
I would have to break my working process.
But why did you implement the msgbox this way
How did you intend it to be used?
That’s my question actually.

This is actually how JavaScript and many modern event-driven GUIs work. Having to poll and wait for a message box necessitates an OS or some other high-level construct to yield to other threads. An event-driven system does not require threads because nothing ever blocks (polls).

This is true in JavaScript as well.

In your case one approach would be to have a second thread which blocks until it receives a signal from your event handler.

1 Like

does lvgl offer a blocking mechanism, or
Do you suggest using an independent freertos task that handles the whole process and waits for the LVGL handlers to signal only?

I think my debugging days using VS are over. :slightly_frowning_face:

Many thanks for your clarification

Yes. LVGL does not provide any mechanism for blocking, as that defeats the whole purpose of using events. The best workaround is to use an independent task like you mentioned, which will effectively give you the same behavior.

1 Like

There should be a way to use semaphores/signals on VS.

1 Like

Many thanks.
I will look it up.

Since the Visual Studio port is using SDL, you could look into using its threading system, which I would expect to be available on Windows.