Skip to content

Commit 651ee88

Browse files
committed
Fixed thread locking in SubclassingWindow - no need to throw in dtor.
1 parent 78e4140 commit 651ee88

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

Rubberduck.VBEEditor/WindowsApi/SubclassingWindow.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ public abstract class SubclassingWindow : IDisposable
1313
private readonly SubClassCallback _wndProc;
1414
private bool _listening;
1515

16-
private static readonly ConcurrentBag<SubClassCallback> RubberduckProcs = new ConcurrentBag<SubClassCallback>();
17-
private static readonly object SubclassLock = new object();
16+
private readonly object _subclassLock = new object();
1817

1918
public delegate int SubClassCallback(IntPtr hWnd, IntPtr msg, IntPtr wParam, IntPtr lParam, IntPtr uIdSubclass, IntPtr dwRefData);
2019

@@ -40,10 +39,6 @@ protected SubclassingWindow(IntPtr subclassId, IntPtr hWnd)
4039
_wndProc = SubClassProc;
4140
AssignHandle();
4241
}
43-
~SubclassingWindow()
44-
{
45-
Debug.Assert(false, "Dispose() not called.");
46-
}
4742

4843
public void Dispose()
4944
{
@@ -53,9 +48,8 @@ public void Dispose()
5348

5449
private void AssignHandle()
5550
{
56-
lock (SubclassLock)
51+
lock (_subclassLock)
5752
{
58-
RubberduckProcs.Add(_wndProc);
5953
var result = SetWindowSubclass(_hwnd, _wndProc, _subclassId, IntPtr.Zero);
6054
if (result != 1)
6155
{
@@ -67,13 +61,13 @@ private void AssignHandle()
6761

6862
private void ReleaseHandle()
6963
{
70-
if (!_listening)
64+
lock (_subclassLock)
7165
{
72-
return;
73-
}
66+
if (!_listening)
67+
{
68+
return;
69+
}
7470

75-
lock (SubclassLock)
76-
{
7771
var result = RemoveWindowSubclass(_hwnd, _wndProc, _subclassId);
7872
if (result != 1)
7973
{

0 commit comments

Comments
 (0)