ESP32S2 and reconnect to wifi

hello I use an ESP32S2 mini and I have an Asus AIMesh Wi-Fi network. From time to time the ESP reconnects to the wrong access point, which causes instabilities due to the bad connection. so I want to make a disconnection/reconnection function to the wifi but from time to time when I execute this function the ESP reboots. I think about watch dogs I can't find a way to avoid this reboot (this same code works well with ESP8266) can someone help me?
thanks!

void reconnectWifi() {
#if defined(ESP8266)
  WiFi.disconnect(true);
  delay(500);
  wifiMulti.run();
#elif defined(ESP32)
  WiFi.disconnect();
  delay(500);
  while (wifiMulti.run() != WL_CONNECTED) {
    Serial.println("WiFi not connected!");
    delay(1000);
  }
#endif
}

One idea would be to deactivate the watchdog during the connection, but everything goes well during the first connection in the setup...

try resetting the watchdog yourself inside of the while loop..

esp_task_wdt_reset();//pat the dog..

esp32/api-reference/system/wdts

Watch dog gets reset on line 72

good luck.. ~q

What makes you think it's a watch dog reset? What does the reset message say?