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

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

问题描述

我已经将FluentFTP库移植到.NET standard/.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 Core上可以做些什么来支持这一点?

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

推荐答案

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

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 实现为真正的异步方法.然后,很容易实现 BeginConnect EndConnect 作为围绕 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天全站免登陆