mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-10-05 04:24:38 +13:00
Log spam protection on COM exceptions while reading icons
This commit is contained in:
parent
2f790b3226
commit
4f1ee5385c
1 changed files with 8 additions and 1 deletions
|
@ -27,6 +27,8 @@ namespace SystemTrayMenu.Utilities
|
||||||
private static readonly ConcurrentDictionary<string, BitmapSource> IconDictCache = new();
|
private static readonly ConcurrentDictionary<string, BitmapSource> IconDictCache = new();
|
||||||
private static readonly BitmapSource? OverlayImage = (BitmapSource?)Application.Current.Resources["LinkArrowIconImage"];
|
private static readonly BitmapSource? OverlayImage = (BitmapSource?)Application.Current.Resources["LinkArrowIconImage"];
|
||||||
|
|
||||||
|
private static int maxCOMExceptionLogs = 5;
|
||||||
|
|
||||||
// see https://github.com/Hofknecht/SystemTrayMenu/issues/209.
|
// see https://github.com/Hofknecht/SystemTrayMenu/issues/209.
|
||||||
internal static bool IsPreloading { get; set; } = true;
|
internal static bool IsPreloading { get; set; } = true;
|
||||||
|
|
||||||
|
@ -203,8 +205,13 @@ namespace SystemTrayMenu.Utilities
|
||||||
catch (COMException ex)
|
catch (COMException ex)
|
||||||
{
|
{
|
||||||
// This seems to happen very rarely, so we just log it and go on
|
// This seems to happen very rarely, so we just log it and go on
|
||||||
|
// 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);
|
Log.Warn("Reading native Icon failed:", ex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
icon?.Dispose();
|
icon?.Dispose();
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue