Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ internal void Complete()
lock (_invokeSyncObject)
{
IsCompleted = true;
_resetEvent?.Set();
try
{
_resetEvent?.Set();
}
catch (ObjectDisposedException)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of catching an exception, can we check: if(!_marshaler.IsDisposed)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. We could have the waitHandle disposed ...

IAsyncResult result = control.BeginInvoke(callback);
result.AsyncWaitHandle.Dispose();

... but not the marshaling control.

{
// AsyncWaitHandle exposes the event and allows callers to dispose it before completion.
}
Comment thread
KlausLoeffelmann marked this conversation as resolved.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4276,6 +4276,21 @@ await Task.Run(() =>
Assert.Equal(0, createdCallCount);
}

[WinFormsFact]
public void Control_BeginInvoke_DisposedAsyncWaitHandle_CompletesCallback()
{
using Control control = new();
Assert.NotEqual(IntPtr.Zero, control.Handle);
bool callbackInvoked = false;
IAsyncResult asyncResult = control.BeginInvoke(() => callbackInvoked = true);
asyncResult.AsyncWaitHandle.Dispose();

control.TestAccessor.Dynamic.InvokeMarshaledCallbacks();

Assert.True(callbackInvoked);
Assert.True(asyncResult.IsCompleted);
}

[WinFormsFact]
public void Control_Invoke_Action_calls_correct_method()
{
Expand Down
Loading