Arduino stops working when pc turned off

Perhaps the PC turning off upsets the DTR/RTS.

Just checked plugged directly into the usb port; Same behaviour - hadnt realised the USB continues to provide power when the PC is "off".

With the ESP32 hardware & sketch (I've added a "flash the LED" to indicate a reset ) I find the system is now doing repeated resets, and never gets the
WiFi.onEvent(WiFiStationConnected, SYSTEM_EVENT_STA_CONNECTED);

IS there something in the arduino code that can trigger a reset?

I havent included the rest of the sketch because with the PC turned OFF it never gets past the "setup"

void setup() {
  Serial.begin(115200);
  pinMode(LED_WiFi, OUTPUT);
  pinMode(LED_Pulse, OUTPUT);
  pinMode(intPin, INPUT_PULLUP);
  digitalWrite(LED_WiFi, 1); //flash blue LED twice to show there has been a reset event
  delay(100);
  digitalWrite(LED_WiFi, 0); 
  delay(100);
  digitalWrite(LED_WiFi, 1); 
  delay(100);
  digitalWrite(LED_WiFi, 0); //ensure blue LED off

  // added in V2.11:  delete old wifi config
  WiFi.disconnect(true);
  delay(200);

  //separate heading from reset diagnostic messages
  Serial.println("");
  Serial.println("Starting Solar Logger");

  //added in V2.11: monitor Wifi connection and handle LED - nb these dont work as is on 8266
  WiFi.onEvent(WiFiStationConnected, SYSTEM_EVENT_STA_CONNECTED);
  WiFi.onEvent(WiFiGotIP, SYSTEM_EVENT_STA_GOT_IP);
  WiFi.onEvent(WiFiStationDisconnected, SYSTEM_EVENT_STA_DISCONNECTED);

  initWiFi();
  delay(200);
  //  FTP Setup, ensure SPIFFS is started before ftp;
  if (SPIFFS.begin(true)) {
    Serial.println("SPIFFS opened!");
    ftpSrv.begin("esp8266", "esp8266");  //ftp username, password. set ports in ESP8266FtpServer.h (default 21, 50009 for PASV)
  }
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);   // Init and get the time
  delay(100); //allow to get NTP time
  while (!getLocalTime(&timeinfo)) {
    delay(100);
  }
  currMonth = 1 + timeinfo.tm_mon; //tm_mon gives months since jan so eg April is 03 hence add 1
  currDay = timeinfo.tm_mday; //set current day
  Serial.printf("Setup: -  success getting time. currMonth is %i: currDay is %i \n", currMonth, currDay);
  //currDay = 0; //testing - force new day scenario
  //currMonth = 0; //testing - force new month scenario
  newMonth();  //if no file exists as yet for month data create one; but if there is one dont overwrite it.

  // Handle Web Server
  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send_P(200, "text/html", index_html, processor);
  });

  // Handle Web Server Events
  events.onConnect([](AsyncEventSourceClient * client) {
    if (client->lastId()) {
      Serial.printf("Client reconnected! Last message ID that it got is: %u\n", client->lastId());
    }
    // send event with message "hello!", id current millis and set reconnect delay to 10 second
    client->send("hello!", NULL, millis(), 10000);
  });
  server.addHandler(&events);
  server.begin();

  zeroStats();
  configInterrupt();
  Serial.println("Setup complete \n");
}