Skip to content

Commit

Permalink
Always dispose after using RegistryKey
Browse files Browse the repository at this point in the history
  • Loading branch information
geforce-hisa0904 committed Aug 15, 2020
1 parent da97286 commit 964b252
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions RunCat/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ private string GetAppsUseTheme()
string keyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize";
try
{
RegistryKey rKey = Registry.CurrentUser.OpenSubKey(keyName);
int theme = (int)rKey.GetValue("SystemUsesLightTheme");
rKey.Close();
return theme == 0 ? "dark" : "light";
using (RegistryKey rKey = Registry.CurrentUser.OpenSubKey(keyName))
{
int theme = (int)rKey.GetValue("SystemUsesLightTheme");
return theme == 0 ? "dark" : "light";
}
}
catch (NullReferenceException)
{
Expand Down

0 comments on commit 964b252

Please sign in to comment.