Hello @Onur Coşkun,
welcome to this moderated Azure community forum.
Based on your code example, I reduced it to just a console app:
It's based on .Net 8 LTS:
This way, the device clients connects within a fraction of a second.
It seems the Azure IoT Device SDK is not the root cause of your issue.
Please check first how your BackgroundService performs without the Device client connection.
If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.