与AppDomain的一个强大的服务器 [英] AppDomains vs. a robust server

查看:224
本文介绍了与AppDomain的一个强大的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在做一些研究后似乎的AppDomain是不是真的为建设一个托管服务器的工具。从我的理解,托管服务器仍然会崩溃,如果有一个创建AppDomain中未处理的异常(如果该异常是从一个线程创建的AppDomain抛出)。因此,在这种情况下,如果托管服务器托管其泄漏的异常,这将拉低默认的AppDomain以及服务。

after doing some research it seems that AppDomains are not really a tool for building a hosting server. From my understanding, the hosting server will still crash if there is an unhandled exception in a created AppDomain (if the exception is thrown from a thread in the created AppDomain). So in that case if the hosting server hosts a service which leaks exceptions this will bring down the default AppDomain as well.

所以,我从服务器架构猜点OF-鉴于没有什么比创建子进程,并监控他们更好。

So I guess from a server architecture point-of-view there is nothing better than creating child processes and monitoring them.

是正确的还是我失去了与AppDomain的东西吗?

Is that correct or am I missing something with AppDomains?

感谢,
克里斯托夫

thanks, Christoph

推荐答案

如果你能控制在对方的AppDomain中创建的线程,可以还可以处理由线程主要方法使用全部模块的异常。

If you can control the threads created in the other AppDomain, you can also handle exceptions by using catch-all blocks in the thread main method.

除此之外,你只要使用默认的主机,我相信你的假设是正确的。但是,如果你自己的主机运行时,你也可以处理未处理的异常。

Other than that, as long as you use the default host, I believe that your assumption is correct. However, if you host the runtime yourself, you can also handle unhandled exceptions.

从的论坛发帖的话题

嗯,这是可能的。你不得不
创建自己的CLR的主机。启动
与ICorBindToRuntimeEx()。你得到
拥有的AppDomain
抛出的异常的完全控制。而且它正在使用MSFT软件如ASP.NET和
SQL Server 2005中当你写一个
服务
,你是用
默认CLR主机实现,它的工作
终止进程时,任何
未处理的异常升高时,
不管是什么AppDomain中造成
除外。

Well, it is possible. You'd have to create your own CLR host. That starts with ICorBindToRuntimeEx(). You get to have full control of AppDomains that throw exceptions. And it's being used by MSFT software like ASP.NET and SQL Server 2005. When you write a service, you are working with the default CLR host implementation and it terminates the process when any unhandled exception is raised, regardless of what AppDomain caused the exception.

但问题是像ASP.NET和SQL
服务器主机有一个非常明确的代码
执行路径。在Web服务器上,
托管代码运行,因为一个页面
要求。在一个dBASE服务器,它运行,因为查询的
。当一些
不好的事情发生,他们有
干脆放弃了
请求开始一切(杀
的AppDomain),并返回一个对不起,
couldn'奢侈品做T它的状态回到
客户端。你可能已经看到了,
拍击古老
网站的论坛服务器是相当微不足道,但没有
从服务于其他请求停止。
实际上没有100%的把握。

Problem is, hosts like ASP.NET and SQL server have a very well defined code execution path. In a web server, managed code runs because of a page request. In a dbase server, it runs because of a query. When something bad happens, they have the luxury of simply aborting everything that the request started (killing the AppDomain) and returning a "sorry, couldn't do it" status back to the client. You might have seen it, crashing the forums server on the old web site was pretty trivial but didn't stop it from serving other requests. Not actually 100% sure about that.

您服务实现
可能几乎没有干净。我不能
告诉,你没有说约
任何事情。它一般情况下,有一个问题
与中止线程。你总是
具有中止一个线程时,有一个
未处理的异常。服务
通常有一个线程,由
的的OnStart()方法启动。中止它
杀死服务器,直到有人停止
,并再次启动它。

Your service implementation is probably not nearly as clean. I can't tell, you didn't say anything about it. It general, there's a problem with aborting a thread. You always have to abort a thread when there's an unhandled exception. A service typically has one thread, started by the OnStart() method. Aborting it kills the server until somebody stops and starts it again.

您绝对可以使其更
较有弹性,你可以开始一个
主线程启动子
线程响应外部事件
,使你的服务做的工作。
有一个子线程终止,因为未处理的异常的

的东西你可能恢复从
。不过,如果你把旁边
步骤,为什么不能有子线程
捕捉异常,并传回给
主线程,因此它可以使一个
智能决策关于下一步做什么

You can definitely make it more resilient than that, you could start a "master" thread that launches child threads in response to external events that makes your service do its job. Having a child thread terminated because of an unhandled exception is something you could possibly recover from. But then, if you make that next step, why not have the child thread catch an exception and pass it back to the master thread so it can make an intelligent decision about what to do next.

默认CLR
主机的冷酷的事实是:如果你不愿意
处理故障,它是不会
为你做这项工作。而且它不应该,
的.NET 1.x的行为线程
有例外死是得到了在.NET
2.0修正的主要
错误。

The cold hard fact of the default CLR host is: if you are not willing to deal with failure, it is not going to do the job for you. And it shouldn't, the .NET 1.x behavior to threads that died with exceptions was a major mistake that got corrected in .NET 2.0.

您知道该怎么做:处理失败。
或写你自己的主机。或接受
的东西可能是你无法控制的
,并记录良好的错误信息,所以你
可以告诉你的客户做什么。
我强烈推荐后者。

You know what to do: handle failure. Or write you own host. Or accept that things could be beyond your control and log a good error message so you can tell your customer what to do. I'd strongly recommend the latter.

这篇关于与AppDomain的一个强大的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆