我的C#应用程序server.exe
对我的业务运营至关重要,理想情况下,它需要24/7不间断地运行。该代码固若金汤,但是我无法控制的是第三方生成的入站数据提要的质量很差。我偶尔会收到包含异常的数据提要,在这种情况下,我必须:
server.exe
以适应异常server.exe
使用新代码重新启动,并允许处理语法上有缺陷的提要整个过程通常花费不到几分钟,但重新启动server.exe
会导致某些非关键状态信息的重置,更糟糕的是,将导致依赖于外部过程的中断server.exe.
我的目标是:将提要处理代码隔离到一个单独的DLL中,该DLL的内容可以在不重新启动的情况下进行更新server.exe
。我该怎么做呢?
在撰写此论坛帖子之前,请允许我解释我到目前为止所做的事情:
供稿处理器接口已移至名为的新程序集common.dll
。该界面如下所示:
public interface IFeedProcessor{
bool ProcessFeed(String filePath); //returns false on failure, true on success
}
Server.exe
现在参考common.dll
。
供稿处理器本身已移至名为的新程序集feedProcessors.dll
。实现看起来像这样:
internal class FeedProcessor1:IFeedProcessor{
public FeedProcessor1(){}
bool ProcessFeed(String filePath){/*implementation*/return true;}
}
internal class FeedProcessor2:IFeedProcessor{
public FeedProcessor2(){}
public bool ProcessFeed(String filePath){/*implementation*/return true;}
}
[... and so on...]
feedProcessors.dll
还包含一个名为的类FeedProcessorUtils
,该类用于根据一些配置输入来创建特定的提要处理器。看起来像这样:
public class FeedProcessorUtils{
public static void CreateFeedProcessor(int feedType /*and other configuration params*/){
switch(feedType){
case 1:return new FeedProcessor1();
case 2:return new FeedProcessor2();
default: throw new ApplicationException("Unhandled feedType: "+feedType);
}
}
}
一切都像以前一样工作,但是当然不能解决我的动态加载问题;如果我feedProcessors.dll
使用新代码进行更新并将其复制到生产服务器,则由于文件正在使用中,因此无法执行此操作。毫不奇怪。那么解决方案是什么呢?
理想情况下,我希望能够将更新内容复制feedProcessors.dll
到生产服务器,而不会出现使用中文件错误并且无需重新启动server.exe
。然后,下一次server.exe
调用FeedProcessorUtils.CreateFeedProcessor(),它将从我修订的DLL中执行,而不是从旧版本中执行。
我从哪里开始?
您要对动态加载的DLL使用卷影复制程序集http://msdn.microsoft.com/zh-cn/library/ms404279(v=vs.110).aspx
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句