System.on(button_click, button_clicked) -> when calling Particle.connect() in button_clicked -> red blinks (Assertion failure)

My code:

void button_clicked(system_event_t event, int param)
{
    int times = system_button_clicks(param);
    Serial.printlnf("setup button was clicked %d times", times);
    Particle.connect();
}

void setup()
{
  System.on(button_click, button_clicked);
}

When I press the setup button, I get red blinks (SOS, 10, SOS 10) - Assertion Failure
When I leave the line ‘Particle.connect()’ out, it works fine.

How can I do this?

//UPDATE
button_final_click event acts the same way

@kenvernaillen, that’s most likely because Particle.connect() is a blocking call. You may want to instead set a flag that you sample or wait for in your setup() or loop() code.