Skip to content

Commit 9fc13f3

Browse files
committed
Improve dispose function
1 parent 53b3b7f commit 9fc13f3

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

Flow.Launcher.Infrastructure/QuickSwitch/Models/WindowsExplorer.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ namespace Flow.Launcher.Infrastructure.QuickSwitch.Models
1212
/// </summary>
1313
public class WindowsExplorer : IQuickSwitchExplorer
1414
{
15-
private static IWebBrowser2 _lastExplorerView = null;
16-
1715
public IQuickSwitchExplorerWindow CheckExplorerWindow(IntPtr hwnd)
1816
{
1917
IQuickSwitchExplorerWindow explorerWindow = null;
@@ -30,7 +28,6 @@ public IQuickSwitchExplorerWindow CheckExplorerWindow(IntPtr hwnd)
3028

3129
if (explorer.HWND != hwnd) return true;
3230

33-
_lastExplorerView = explorer;
3431
explorerWindow = new WindowsExplorerWindow(hwnd, explorer);
3532
return false;
3633
}
@@ -75,19 +72,7 @@ private static unsafe void EnumerateShellWindows(Func<object, bool> action)
7572

7673
public void Dispose()
7774
{
78-
// Release ComObjects
79-
try
80-
{
81-
if (_lastExplorerView != null)
82-
{
83-
Marshal.ReleaseComObject(_lastExplorerView);
84-
_lastExplorerView = null;
85-
}
86-
}
87-
catch (COMException)
88-
{
89-
_lastExplorerView = null;
90-
}
75+
9176
}
9277
}
9378

@@ -159,7 +144,19 @@ public string GetExplorerPath()
159144

160145
public void Dispose()
161146
{
162-
147+
// Release ComObjects
148+
try
149+
{
150+
if (_explorerView != null)
151+
{
152+
Marshal.ReleaseComObject(_explorerView);
153+
_explorerView = null;
154+
}
155+
}
156+
catch (COMException)
157+
{
158+
_explorerView = null;
159+
}
163160
}
164161
}
165162
}

0 commit comments

Comments
 (0)