How to solve this problem?

It’s not possible to cancel an in-progress background task – but you can try to stop/start your SonarQube instance.

If the background task is taking a long time – the culprit is likely poor performance of your SonarQube server or the database it’s connected to. What database platform are you using with SonarQube (the embedded H2 database, postgres, oracle, SQL server?)