CreateInstanceFromAndUnwrap 速度和优化
我正在开发一个项目,我们必须将一些包含大量 C# 静态变量的遗留代码包装到 WCF 服务中。正如您可以想象的那样,这对于请求应该是无状态的 WCF 服务来说是一场噩梦。
如果没有重大重写,我能想到的最佳解决方案是在单独的 AppDomain 中执行遗留代码,因此它是线程安全的,我使用 CreateInstanceFromAndUnwrap() 来实现这一点。
我让代码正常工作,但问题是它非常慢,因为现在对于每个 WCF 请求,它都必须在代码开始执行之前将所有 20 多个 DLL 重新加载到 AppDomain 中。
我只是想知道有人知道如何优化 CreateInstanceFromAndUnwrap() 吗?例如,我是否可以预加载所有程序集而不加载类,以便每次收到请求时都会重置静态变量?
干杯, 奥斯卡
I'm working on a project where we have to wrap some legacy code that contains a lot of C# static variables into a WCF service. As you can imagine, this is a nightmare for a WCF service where requests should be state-less.
Without a major rewrite the best solution I can come up with is to execute the legacy code in a separate AppDomain so it is thread safe and I used CreateInstanceFromAndUnwrap() to achieve this.
I got the code working but the problem is it's pretty slow because now for every single WCF request it has to reload all 20+ DLLs into a AppDomain before the code even start executing.
I'm just wondering does anyone know how to optimize CreateInstanceFromAndUnwrap()? For example, is there anyway I can pre-load all assemblies without loading the class in so the static variables will be reset everytime a request comes in?
Cheers,
Oscar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于不知道如何才能准确地完成您所要求的事情,至少我想分享我对此事的想法:
Short of knowing how you could do exactly what you are asking for, at least I want to share my thoughts on the matter: