Skip to content

Commit ac486b2

Browse files
committed
Make UI thread mandatory for use of DoEvents. Update description.
1 parent 274f8c4 commit ac486b2

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Rubberduck.Parsing/UIContext/UiDispatcher.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,23 @@ public static void Shutdown()
123123
/// <summary>
124124
/// Used to pump any pending COM messages. This should be used only as a part of
125125
/// synchronizing or to effect a block until all other threads has finished with
126-
/// their pending COM calls.
126+
/// their pending COM calls. This should be used by the UI thread **ONLY**.
127127
/// </summary>
128-
public static void DoEvents()
128+
/// <remarks>
129+
/// Typical use would be within a event handler for an event belonging to a COM
130+
/// object which require some synchronization with COM accesses from other threads.
131+
/// Events raised by COM are on UI thread by definition.
132+
/// </remarks>
133+
public static int DoEvents()
129134
{
130-
Invoke(() => ExecuteDoEvents());
135+
CheckInitialization();
136+
137+
if (UiContext != SynchronizationContext.Current)
138+
{
139+
throw new InvalidOperationException("DoEvents cannot be used in other threads");
140+
}
141+
142+
return ExecuteDoEvents();
131143
}
132144

133145
private static int ExecuteDoEvents()

0 commit comments

Comments
 (0)