mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-07-09 08:16:41 +12:00
Log spam protection on COM exceptions while reading icons
This commit is contained in:
parent
2f790b3226
commit
4f1ee5385c
|
@ -27,6 +27,8 @@ namespace SystemTrayMenu.Utilities
|
|||
private static readonly ConcurrentDictionary<string, BitmapSource> IconDictCache = new();
|
||||
private static readonly BitmapSource? OverlayImage = (BitmapSource?)Application.Current.Resources["LinkArrowIconImage"];
|
||||
|
||||
private static int maxCOMExceptionLogs = 5;
|
||||
|
||||
// see https://github.com/Hofknecht/SystemTrayMenu/issues/209.
|
||||
internal static bool IsPreloading { get; set; } = true;
|
||||
|
||||
|
@ -203,7 +205,12 @@ namespace SystemTrayMenu.Utilities
|
|||
catch (COMException ex)
|
||||
{
|
||||
// This seems to happen very rarely, so we just log it and go on
|
||||
Log.Warn("Reading native Icon failed:", ex);
|
||||
// However, we protect this log message from being called often, so we stop logging after a while
|
||||
if (maxCOMExceptionLogs > 0)
|
||||
{
|
||||
maxCOMExceptionLogs--; // Note: written by multiple threads, but it is not worth any protection
|
||||
Log.Warn("Reading native Icon failed:", ex);
|
||||
}
|
||||
}
|
||||
|
||||
icon?.Dispose();
|
||||
|
|
Loading…
Reference in a new issue