diff --git a/src/components/BootstrapBlazor.IP2Region/BootstrapBlazor.IP2Region.csproj b/src/components/BootstrapBlazor.IP2Region/BootstrapBlazor.IP2Region.csproj index 2d9ed946..20aba966 100644 --- a/src/components/BootstrapBlazor.IP2Region/BootstrapBlazor.IP2Region.csproj +++ b/src/components/BootstrapBlazor.IP2Region/BootstrapBlazor.IP2Region.csproj @@ -1,7 +1,7 @@  - 9.0.2 + 9.0.3 diff --git a/src/components/BootstrapBlazor.IP2Region/Services/IP2RegionService.cs b/src/components/BootstrapBlazor.IP2Region/Services/IP2RegionService.cs index 7717591b..56fcfa0e 100644 --- a/src/components/BootstrapBlazor.IP2Region/Services/IP2RegionService.cs +++ b/src/components/BootstrapBlazor.IP2Region/Services/IP2RegionService.cs @@ -9,7 +9,7 @@ namespace BootstrapBlazor.Components; /// -/// 默认 IP2Region 实现 +/// 默认 IP2Region 实现 /// class IP2RegionService : DefaultIpLocatorProvider { @@ -25,26 +25,29 @@ public IP2RegionService(IOptions options, IOptions _options; private readonly IOptions _ipOptions; private readonly ILogger _logger; + private readonly TaskCompletionSource _tcs = new(); private Searcher? _search; /// /// /// /// - protected override Task LocateByIp(string ip) + protected override async Task LocateByIp(string ip) { + await _tcs.Task; + string? result = null; if (_search != null && _options.Value.WebClientOptions.EnableIpLocator) { result = _search.Search(ip); } - return Task.FromResult(result); + return result; } private void InitSearch() @@ -60,9 +63,11 @@ private void InitSearch() { _search = new Searcher(CachePolicy.Content, xdbPath); _logger.LogInformation("IP2Region xdb file {dbPath} loaded", xdbPath); + _tcs.TrySetResult(); } catch (Exception ex) { + _tcs.TrySetException(ex); _logger.LogError(ex, "IP2Region xdb file path: {dbPath}", xdbPath); } }