From 67ccd31a6a855051eed9ca010c02b78f4e6d1079 Mon Sep 17 00:00:00 2001 From: nenad0707 Date: Tue, 4 Jun 2024 23:36:32 +0200 Subject: [PATCH] Added retry to start api --- TaskTackler/App.razor | 5 +++-- TaskTackler/Helpers/PingHelper.cs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/TaskTackler/App.razor b/TaskTackler/App.razor index c9a8e44..5f4f102 100644 --- a/TaskTackler/App.razor +++ b/TaskTackler/App.razor @@ -16,10 +16,11 @@ @code { - protected override async Task OnInitializedAsync() + protected override void OnInitialized() { var httpClient = HttpClientFactory.CreateClient("api"); - await PingHelper.PingApiWithRetry(httpClient); + // Start the pinging process on a background thread + _ = Task.Run(() => PingHelper.PingApiWithRetry(httpClient)); } } diff --git a/TaskTackler/Helpers/PingHelper.cs b/TaskTackler/Helpers/PingHelper.cs index 022e439..28ad310 100644 --- a/TaskTackler/Helpers/PingHelper.cs +++ b/TaskTackler/Helpers/PingHelper.cs @@ -18,8 +18,8 @@ public static async Task PingApi(HttpClient httpClient) public static async Task PingApiWithRetry(HttpClient httpClient) { - const int maxAttempts = 5; - const int delay = 5000; // 5 seconds delay between retries + const int maxAttempts = 10; // Increase the number of attempts + const int delay = 2000; // Reduce the delay to 2 seconds between retries for (int attempt = 0; attempt < maxAttempts; attempt++) {