-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a ConcurrentDictionary to remember which calls did work (#1147)
- Loading branch information
1 parent
b84a28d
commit 9d572ea
Showing
3 changed files
with
32 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,18 +16,31 @@ | |
//$Authors = Jiri Cincura ([email protected]) | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
|
||
namespace FirebirdSql.Data.Common; | ||
|
||
internal static class NativeHelpers | ||
{ | ||
public static void CallIfExists(Action action) | ||
private static readonly ConcurrentDictionary<string, bool> _cache = new ConcurrentDictionary<string, bool>(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) | ||
{ } | ||
} | ||
} |