Skip to content

Commit 89a9fd9

Browse files
committed
Re-re-fix issue #909
1 parent 228ea79 commit 89a9fd9

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

Rubberduck.VBEEditor/VBEHost/HostApplicationBase.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ protected HostApplicationBase(string applicationName)
2626

2727
~HostApplicationBase()
2828
{
29-
if (Application != null)
30-
{
31-
Marshal.ReleaseComObject(Application);
32-
}
29+
Dispose(false);
3330
}
3431

3532
public string ApplicationName
@@ -41,6 +38,11 @@ public string ApplicationName
4138

4239
public TimeSpan TimedMethodCall(QualifiedMemberName qualifiedMemberName)
4340
{
41+
if (_disposed)
42+
{
43+
throw new ObjectDisposedException(GetType().Name);
44+
}
45+
4446
var stopwatch = Stopwatch.StartNew();
4547

4648
Run(qualifiedMemberName);
@@ -52,16 +54,26 @@ public TimeSpan TimedMethodCall(QualifiedMemberName qualifiedMemberName)
5254
public void Dispose()
5355
{
5456
Dispose(true);
57+
GC.SuppressFinalize(this);
5558
}
5659

60+
private bool _disposed;
5761
protected virtual void Dispose(bool disposing)
5862
{
59-
if (!disposing) { return; }
60-
61-
if (Application != null)
63+
if (_disposed) { return; }
64+
65+
// clean up managed resources
66+
if (Application != null)
6267
{
6368
Marshal.ReleaseComObject(Application);
6469
}
70+
71+
if (disposing)
72+
{
73+
// we don't have any managed resources to clean up right now.
74+
}
75+
76+
_disposed = true;
6577
}
6678
}
6779
}

0 commit comments

Comments
 (0)