Improve compatibility with .NET Core and later (including .NET 5 and above) #141
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
.NET Core and later (includes .NET Platform 5 and above) no longer supports delegate
BeginInvoke
andEndInvoke
. See e.g. this blog post from Mike Rousos for details. I changed the corresponding code inHidDevice.cs
andHidFastReadDevice.cs
to useTask
instead.Note I only tested this with .NET 6.0.
The changes should work on .NET Core and .NET Platform 5 and above. They should also work on .NET framework 4.5 and above, since the corresponding features (
Task.Run()
,Task.ContinueWith()
,Task.Factory
andTaskFactory.StartNew()
) are available there also according to the docs.I also modified some code provided earlier in two regards:
TaskFactory.StartNew()
instead of usingdelegate.Invoke()
(needs less code and is easier to read),#if
switches fromNET5_0_OR_GREATER
toNETCOREAPP1_0_OR_GREATER
, since that should be the appropriate symbol according to the docs.Note: On .NET Platform 6 at least, the dependency on the
Theraot.Core
nuget can be removed, because the corresponding backport is no longer needed there.Any review is appreciated. Hope this helps others using this library.