Skip to content

Commit bf8409c

Browse files
committed
Fix up vbeEVents to be reloaded when the add-in has been reloaded because statics do not die at addin's end. Instead, we keep the _terminated variable as a static variable which is reset internally to communicate the state.
1 parent a4928e6 commit bf8409c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Rubberduck.VBEEditor/Events/VbeEvents.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ public sealed class VbeEvents : IVbeEvents
1515
private readonly Dictionary<string, IVBComponents> _components;
1616
private readonly Dictionary<string, IReferences> _references;
1717

18+
private static long _terminated;
19+
private const long _true = 1;
20+
private const long _false = 0;
21+
1822
public static VbeEvents Initialize(IVBE vbe)
1923
{
2024
lock (_instanceLock)
2125
{
2226
if (_instance == null)
2327
{
2428
_instance = new VbeEvents(vbe);
29+
Interlocked.Exchange(ref _terminated, _false);
2530
}
2631
}
2732

@@ -38,6 +43,7 @@ public static void Terminate()
3843
}
3944

4045
_instance.TerminateInternal();
46+
_instance = null;
4147
}
4248
}
4349

@@ -232,8 +238,6 @@ private void ProjectReferenceRemovedHandler(object sender, ReferenceEventArgs e)
232238

233239
public event EventHandler EventsTerminated;
234240

235-
private long _terminated;
236-
private const long _true = 1;
237241
public bool Terminated => Interlocked.Read(ref _terminated) == _true;
238242

239243
private void TerminateInternal()

0 commit comments

Comments
 (0)