Simplest way to make cross-appdomain call?

我们两清 提交于 2019-11-26 18:28:29

问题


I need to call a method of object in another appdomain (pass param and get result). Ideas?

UPD both AppDomain's are created not by my code (host app creates it, and then my code gets called). How I can get access to one AppDomain from another?


回答1:


If you created an object in another domain e.g. with AppDomain.CreateInstanceAndUnwrap, all you need to call the object in another domain is to call an object's method.

The simplest way to make a cross-application domain call is just to make a call directly on that object, which actually is exposed from another domain via its proxy, existing in another domain.

UPD
Unfortunately getting the host domain is not that easy. You should enumerate domains like this and find among them the host one. I suppose that your host domain is the one for which the method AppDomain.IsDefaultAppDomain returns true.




回答2:


This is usually achieved using AppDomain.DoCallBack. You need to make sure that if you want to pass parameters, you need to create a serializable object, whose method you pass to the method described above. In the callback method you can perform another AppDomain callback to pass the result back to the original AppDomain.



来源:https://stackoverflow.com/questions/6242573/simplest-way-to-make-cross-appdomain-call

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