在 .net framework 代码迁移至 .net core 时需要注意 BeginInvoke 不再被支持

参考:https://devblogs.microsoft.com/dotnet/migrating-delegate-begininvoke-calls-for-net-core/

https://github.com/dotnet/runtime/issues/16312

具体表现是代码编译很正常,但是在运行过程中,一旦触发就会报异常:

System.PlatformNotSupportedException: Operation is not supported on this platform.

   at System.Action`1.BeginInvoke(T obj, AsyncCallback callback, Object object)

嗯,就是 BeginInvoke 的锅。。。

解决方案就是使用 Task.Run 来替换 BeginInvoke 即可,按文章里的说法,就是从 APM 换到 TAP,原来的这种方式不再推荐。


输了你,赢了世界又如何...
原文地址:https://www.cnblogs.com/xwgli/p/15260821.html