invoke - p/invoke

给你一囗甜甜゛ 提交于 2019-12-11 06:27:44

问题


what is the difference between BeginInvoke/EndInvoke and P/invoke?


回答1:


They only have the verb "invoke" in common. Generically, invoke == call. The p in pinvoke means "platform", the pinvoke marshaller is a chunk of code inside the CLR that knows how to properly call native (platform specific) code.

BeginInvoke is a heavily overloaded method name that starts an asynchronous method call. The compiler automatically generates one for every delegate type. Along with Invoke and EndInvoke. They are auto-generated so their arguments match the delegate declaration. A BeginInvoke method is also used by Winforms and WPF, respectively the Control and Dispatcher classes. Quite a different animal from a delegate's BeginInvoke() method, although it does start something asynchronously.




回答2:


BeginInvoke/EndInvoke are used in asynchronous programming to invoke a delegate on another thread. P/invoke is used to call unmanaged code.



来源:https://stackoverflow.com/questions/4906674/invoke-p-invoke

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!