File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed
Rubberduck.VBEEditor/VBEHost Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -26,10 +26,7 @@ protected HostApplicationBase(string applicationName)
26
26
27
27
~ HostApplicationBase ( )
28
28
{
29
- if ( Application != null )
30
- {
31
- Marshal . ReleaseComObject ( Application ) ;
32
- }
29
+ Dispose ( false ) ;
33
30
}
34
31
35
32
public string ApplicationName
@@ -41,6 +38,11 @@ public string ApplicationName
41
38
42
39
public TimeSpan TimedMethodCall ( QualifiedMemberName qualifiedMemberName )
43
40
{
41
+ if ( _disposed )
42
+ {
43
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
44
+ }
45
+
44
46
var stopwatch = Stopwatch . StartNew ( ) ;
45
47
46
48
Run ( qualifiedMemberName ) ;
@@ -52,16 +54,26 @@ public TimeSpan TimedMethodCall(QualifiedMemberName qualifiedMemberName)
52
54
public void Dispose ( )
53
55
{
54
56
Dispose ( true ) ;
57
+ GC . SuppressFinalize ( this ) ;
55
58
}
56
59
60
+ private bool _disposed ;
57
61
protected virtual void Dispose ( bool disposing )
58
62
{
59
- if ( ! disposing ) { return ; }
60
-
61
- if ( Application != null )
63
+ if ( _disposed ) { return ; }
64
+
65
+ // clean up managed resources
66
+ if ( Application != null )
62
67
{
63
68
Marshal . ReleaseComObject ( Application ) ;
64
69
}
70
+
71
+ if ( disposing )
72
+ {
73
+ // we don't have any managed resources to clean up right now.
74
+ }
75
+
76
+ _disposed = true ;
65
77
}
66
78
}
67
79
}
You can’t perform that action at this time.
0 commit comments