@@ -16,7 +16,7 @@ public static class WallpaperPathRetrieval
16
16
{
17
17
private static readonly int MAX_PATH = 260 ;
18
18
19
- private static readonly Dictionary < DateTime , ImageBrush > wallpaperCache = new ( ) ;
19
+ private static readonly Dictionary < ( string , DateTime ) , ImageBrush > wallpaperCache = new ( ) ;
20
20
21
21
public static Brush GetWallpaperBrush ( )
22
22
{
@@ -26,20 +26,20 @@ public static Brush GetWallpaperBrush()
26
26
return Application . Current . Dispatcher . Invoke ( GetWallpaperBrush ) ;
27
27
}
28
28
29
- var wallpaper = GetWallpaperPath ( ) ;
30
- if ( wallpaper is not null && File . Exists ( wallpaper ) )
29
+ var wallpaperPath = GetWallpaperPath ( ) ;
30
+ if ( wallpaperPath is not null && File . Exists ( wallpaperPath ) )
31
31
{
32
- // Since the wallpaper file name is the same (TranscodedWallpaper),
33
- // we need to use the last modified date to differentiate them
34
- var dateModified = File . GetLastWriteTime ( wallpaper ) ;
35
- wallpaperCache . TryGetValue ( dateModified , out var cachedWallpaper ) ;
32
+ // Since the wallpaper file name can be the same (TranscodedWallpaper),
33
+ // we need to add the last modified date to differentiate them
34
+ var dateModified = File . GetLastWriteTime ( wallpaperPath ) ;
35
+ wallpaperCache . TryGetValue ( ( wallpaperPath , dateModified ) , out var cachedWallpaper ) ;
36
36
if ( cachedWallpaper != null )
37
37
{
38
38
return cachedWallpaper ;
39
39
}
40
40
41
41
// We should not dispose the memory stream since the bitmap is still in use
42
- var memStream = new MemoryStream ( File . ReadAllBytes ( wallpaper ) ) ;
42
+ var memStream = new MemoryStream ( File . ReadAllBytes ( wallpaperPath ) ) ;
43
43
var bitmap = new BitmapImage ( ) ;
44
44
bitmap . BeginInit ( ) ;
45
45
bitmap . StreamSource = memStream ;
@@ -49,7 +49,7 @@ public static Brush GetWallpaperBrush()
49
49
bitmap . Freeze ( ) ; // Make the bitmap thread-safe
50
50
var wallpaperBrush = new ImageBrush ( bitmap ) { Stretch = Stretch . UniformToFill } ;
51
51
wallpaperBrush . Freeze ( ) ; // Make the brush thread-safe
52
- wallpaperCache . Add ( dateModified , wallpaperBrush ) ;
52
+ wallpaperCache . Add ( ( wallpaperPath , dateModified ) , wallpaperBrush ) ;
53
53
return wallpaperBrush ;
54
54
}
55
55
0 commit comments