在 .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,原來的這種方式不再推薦。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM