diff --git a/src/FirebirdSql.Data.FirebirdClient/Client/Native/FbClientFactory.cs b/src/FirebirdSql.Data.FirebirdClient/Client/Native/FbClientFactory.cs index 98bc44bd8..c816d19a6 100644 --- a/src/FirebirdSql.Data.FirebirdClient/Client/Native/FbClientFactory.cs +++ b/src/FirebirdSql.Data.FirebirdClient/Client/Native/FbClientFactory.cs @@ -83,7 +83,7 @@ public static IFbClient Create(string dllName) { result = BuildFbClient(dllName); cache.Add(dllName, result); - ShutdownHelper.RegisterFbClientShutdown(() => NativeHelpers.CallIfExists(() => result.fb_shutdown(0, 0))); + ShutdownHelper.RegisterFbClientShutdown(() => NativeHelpers.CallIfExists(nameof(IFbClient.fb_shutdown), () => result.fb_shutdown(0, 0))); return result; } finally diff --git a/src/FirebirdSql.Data.FirebirdClient/Client/Native/FesStatement.cs b/src/FirebirdSql.Data.FirebirdClient/Client/Native/FesStatement.cs index 8d29d76db..6dc7de2fb 100644 --- a/src/FirebirdSql.Data.FirebirdClient/Client/Native/FesStatement.cs +++ b/src/FirebirdSql.Data.FirebirdClient/Client/Native/FesStatement.cs @@ -371,11 +371,13 @@ public override void Execute(int timeout, IDescriptorFiller descriptorFiller) descriptorFiller.Fill(_parameters, 0); ClearStatusVector(); - NativeHelpers.CallIfExists(() => - { - _database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout); - _database.ProcessStatusVector(_statusVector); - }); + NativeHelpers.CallIfExists( + nameof(IFbClient.fb_dsql_set_timeout), + () => + { + _database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout); + _database.ProcessStatusVector(_statusVector); + }); ClearStatusVector(); @@ -441,11 +443,13 @@ public override async ValueTask ExecuteAsync(int timeout, IDescriptorFiller desc await descriptorFiller.FillAsync(_parameters, 0, cancellationToken).ConfigureAwait(false); ClearStatusVector(); - NativeHelpers.CallIfExists(() => - { - _database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout); - _database.ProcessStatusVector(_statusVector); - }); + NativeHelpers.CallIfExists( + nameof(IFbClient.fb_dsql_set_timeout), + () => + { + _database.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout); + _database.ProcessStatusVector(_statusVector); + }); ClearStatusVector(); diff --git a/src/FirebirdSql.Data.FirebirdClient/Common/NativeHelpers.cs b/src/FirebirdSql.Data.FirebirdClient/Common/NativeHelpers.cs index f3450e781..25d65ae9d 100644 --- a/src/FirebirdSql.Data.FirebirdClient/Common/NativeHelpers.cs +++ b/src/FirebirdSql.Data.FirebirdClient/Common/NativeHelpers.cs @@ -16,18 +16,31 @@ //$Authors = Jiri Cincura (jiri@cincura.net) using System; +using System.Collections.Concurrent; namespace FirebirdSql.Data.Common; internal static class NativeHelpers { - public static void CallIfExists(Action action) + private static readonly ConcurrentDictionary _cache = new ConcurrentDictionary(StringComparer.Ordinal); + + public static void CallIfExists(string actionId, Action action) { - try + if (!_cache.TryGetValue(actionId, out var executionAllowed)) + { + try + { + action(); + _cache.TryAdd(actionId, true); + } + catch (EntryPointNotFoundException) + { + _cache.TryAdd(actionId, false); + } + } + else if (executionAllowed) { action(); } - catch (EntryPointNotFoundException) - { } } }