开发者

How Do I get the current instance from an AppDomain?

I use the default appdomain (AD) which I use to create new appdomains (AD1) when required for running plugins in isolation. When creating the new domain I also wire up the AppDomainUnload event to allow me to call clean up code etc.

The issue I seem to have is:

1) Create AD1 from AD

2) Run code in AD1

3) Call AD.Unload(AD1)

The code switches to AD1 and calls the unloading event passing in a reference to the current AppDomain (AD1).

At this point I'd like to get a reference to the current instance running in AD1 to call a shutdown method however there is no GetInstance on the AppDomain class.开发者_运维问答

Any ideas how I can go about getting it?


When you create the instance in AD1, you could either store the instance in a static variable in the AppDoman, statics are scoped to the AppDomain. Alternatively if this is not a singleton type object, you can maintain a List<> of the objects in the AppDomain.

You could put this "registration" in the constructor of your plug-in instance. When handling the Unload you can use either the static or enumerate the list and perform the required clean-up on the object(s).


Are you looking for AppDomain.CurrentDomain?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜