Skip to content

Commit 2f96215

Browse files
committed
NetMQPoller implements ISynchronizeInvoke for all targets
This was previously only for NET40, but actually ISynchronizeInvoke is available in all supported target frameworks now, and there's no reason to exclude it in any of them.
1 parent 4ad6a02 commit 2f96215

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/NetMQ.Tests/NetMQPollerTest.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,6 @@ public async Task TwoThreads()
990990

991991
#region ISynchronizeInvoke tests
992992

993-
#if NET451
994993
[Fact]
995994
public void ISynchronizeInvokeWorks()
996995
{
@@ -1012,8 +1011,7 @@ public void ISynchronizeInvokeWorks()
10121011
Assert.True(isCorrectThread);
10131012
}
10141013
}
1015-
#endif
10161014

1017-
#endregion
1015+
#endregion
10181016
}
10191017
}

src/NetMQ/NetMQPoller.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.ComponentModel;
45
using System.Diagnostics;
56
using System.Linq;
67
using System.Net.Sockets;
78
using System.Threading;
8-
using NetMQ.Core.Utils;
99
using System.Threading.Tasks;
10+
using NetMQ.Core.Utils;
1011

1112
using Switch = NetMQ.Core.Utils.Switch;
1213

@@ -17,6 +18,7 @@ namespace NetMQ
1718
/// </summary>
1819
public sealed class NetMQPoller :
1920
TaskScheduler,
21+
ISynchronizeInvoke,
2022
#pragma warning disable 618 // Type or member is obsolete
2123
INetMQPoller, ISocketPollableCollection, IEnumerable, IDisposable
2224
#pragma warning restore 618 // Type or member is obsolete
@@ -737,10 +739,9 @@ public void Dispose()
737739

738740
#region ISynchronizeInvoke
739741

740-
#if NET40
741-
IAsyncResult ISynchronizeInvoke.BeginInvoke(Delegate method, object[] args)
742+
IAsyncResult ISynchronizeInvoke.BeginInvoke(Delegate method, object?[]? args)
742743
{
743-
var task = new Task<object>(() => method.DynamicInvoke(args));
744+
var task = new Task<object?>(() => method.DynamicInvoke(args));
744745
task.Start(this);
745746
return task;
746747
}
@@ -751,18 +752,17 @@ object ISynchronizeInvoke.EndInvoke(IAsyncResult result)
751752
return task.Result;
752753
}
753754

754-
object ISynchronizeInvoke.Invoke(Delegate method, object[] args)
755+
object? ISynchronizeInvoke.Invoke(Delegate method, object?[]? args)
755756
{
756757
if (CanExecuteTaskInline)
757758
return method.DynamicInvoke(args);
758759

759-
var task = new Task<object>(() => method.DynamicInvoke(args));
760+
var task = new Task<object?>(() => method.DynamicInvoke(args));
760761
task.Start(this);
761762
return task.Result;
762763
}
763764

764765
bool ISynchronizeInvoke.InvokeRequired => !CanExecuteTaskInline;
765-
#endif
766766

767767
#endregion
768768
}

0 commit comments

Comments
 (0)