Force Display Update with Blocking Functions

Description

Manually Force the Display Update

What MCU/Processor/Board and compiler are you using?

ESP32 ILI9341 with SPI Interface

What LVGL version are you using?

8.3.4

What do you want to achieve?

Some part of my software is blocking in nature, it takes a lot of time actually to execute, let’s say 5 seconds.
My understanding unless lv_task_handler(); function is called display will not be updated.
My situation is, the microcontroller starts, and it processes something which takes around 5 seconds, and before calling this blocking function I want to display a wait message using a message box so that the user is aware that something is happening.

What have you tried so far?

I tried calling the function lv_refr_now(NULL); but this doesn’t work, and similarly, I tried calling the function lv_task_handler directly.
I know I am doing something wrong, and there must be something available for this, which I couldn’t find.

Code to reproduce

I think the whole code is not needed, but I will share some important parts with comments.
The following function is called when someone presses the “Re-Scan” button.

void ReScanWiFiSSID(lv_event_t * e)
{
  static lv_obj_t *msg_box;
  // a message box object is created, which is used to display a message to the user
  // that some processing is happening in the background and one should wait
  msg_box = lv_msgbox_create( NULL, "Re-Scanning", \
                              "Please Wait, getting WiFi SSID", \
                              NULL, false );
  lv_obj_center(msg_box);
  // I added these to function, I thought this forced the display update, but this is not the case
  lv_refr_now(NULL);
  // lv_task_handler();
  // these two functions are functions which take around 5 seconds of time
  WiFi_Init();
  WiFi_ScanSSID();
  // and once this function execution is completed, the msg box is closed
  lv_msgbox_close( msg_box );
}

But I can’t see the msg box, and the reason is clear to me, I created the msg box, closes the msg box and then LVGL works and for it, and nothing changed.
If I comment the line lv_msgbox_close( msg_box ); then I can see the message box after 5 seconds, but this is not what I wanted.

Screenshot and/or video

Let me know if some more information is needed.

Any suggestions? Please