Skip to content

Commit 4005054

Browse files
authored
implement the complete IDisposable pattern
1 parent 874a785 commit 4005054

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,31 @@ private static Result CreateThemeResult(string theme, int score, IList<int> high
8383
};
8484
}
8585

86-
public void Dispose()
86+
private bool disposed;
87+
protected virtual void Dispose(bool disposing)
8788
{
88-
if (context != null && context.API != null)
89+
if (!disposed)
8990
{
90-
context.API.VisibilityChanged -= OnVisibilityChanged;
91+
if (disposing)
92+
{
93+
// Dispose managed resources
94+
if (context?.API != null)
95+
{
96+
context.API.VisibilityChanged -= OnVisibilityChanged;
97+
}
98+
}
99+
// Free unmanaged resources
100+
disposed = true;
91101
}
92102
}
103+
~ThemeSelector()
104+
{
105+
Dispose(false);
106+
}
107+
public void Dispose()
108+
{
109+
Dispose(true);
110+
GC.SuppressFinalize(this);
111+
}
93112
}
94113
}

0 commit comments

Comments
 (0)