.NET 核心不支持 BeginInvoke?(PlatformNotSupported 异常) [英] BeginInvoke not supported on .NET core? (PlatformNotSupported exception)

查看:49
本文介绍了.NET 核心不支持 BeginInvoke?(PlatformNotSupported 异常)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将库 FluentFTP 移植到 .NET 标准/.NET 核心,但异步方法在 async/await 块中使用 BeginInvoke.所以它是这样的:

I've ported a library FluentFTP to .NET standard/.NET core but the async methods use BeginInvoke within an async/await block. So its something like this:

async ConnectAsync(){
   BeginConnect();
}
void BeginConnect(){
   BeginInvoke(...)   << error at this point
}

那时我收到 PlatformNotSupported 异常.可以做些什么来在 .NET 核心上支持这一点?

At that point I get a PlatformNotSupported exception. What can be done to support this on .NET core?

推荐答案

异步 ​​I/O 方法不应使用 Delegate.BeginInvoke.这暴露了一个 fake-asynchronous wrapper 用于首先应该是异步的同步方法.整个设计需要重新评估.

Asynchronous I/O methods should not use Delegate.BeginInvoke. That's exposing a fake-asynchronous wrapper for a synchronous method that should be asynchronous in the first place. The whole design needs re-evaluation.

.NET Core 不支持 Delegate.BeginInvoke出于很好的理由..NET Core 2.0 可能会决定支持它们(因为 Microsoft IMO 在 v2 中做出了一些糟糕的设计决策).

.NET Core does not support Delegate.BeginInvoke for very good reasons. It's possible that .NET Core 2.0 may decide to support them (because Microsoft IMO is making some poor design decisions with v2).

但是回到原来的问题:解决方法是执行//TODO:将ConnectAsync 实现为真正的异步方法.然后将 BeginConnectEndConnect 实现为 ConnectAsync 的包装器非常简单.

But back to the original problem: the solution is to do the //TODO: implement ConnectAsync as a true asynchronous method. Then it's pretty straightforward to implement BeginConnect and EndConnect as wrappers around ConnectAsync.

这篇关于.NET 核心不支持 BeginInvoke?(PlatformNotSupported 异常)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆