加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#面试问题

发布时间:2020-12-15 03:54:25 所属栏目:百科 来源:网络整理
导读:这是我需要帮助的面试问题. 您有以下ASP.NET代码隐藏类: public partial class Page1 : Page { private string _value; public Page1() { if (DateTime.Now.Ticks % 10 == 0) _value = "Test"; } ~Page1() { if(_value.Equals("Test")) _value = string.Emp
这是我需要帮助的面试问题.

您有以下ASP.NET代码隐藏类:

public partial class Page1 : Page 
{
    private string _value;

    public Page1() 
    {
        if (DateTime.Now.Ticks % 10 == 0)
            _value = "Test";
    }       

    ~Page1() 
    {
        if(_value.Equals("Test"))
            _value = string.Empty;      
    }
}

任何有人请求此页面,w3wp.exe进程意外终止.

>为什么会发生与用户看到黄色屏幕死亡(默认的ASP.NET错误页面)?
>为什么托管堆上总是出现OutOfMemoryException?

解决方法

提示:永远不会在析构函数/ finalizer中抛出异常,否则将会杀死GC运行的线程,而GC中的线程可能会变得丑陋.

虽然在.NET 1.1中有一些容忍在后台线程中抛出的异常,这些异常已被使用,并且不会使主机进程停止,但从CLR 2.0开始就不再这样了. Quote from the doc:

If Finalize or an override of Finalize
throws an exception,and the runtime
is not hosted by an application that
overrides the default policy,the
runtime terminates the process and no
active try-finally blocks or
finalizers are executed. This behavior
ensures process integrity if the
finalizer cannot free or destroy
resources.

在终结者中抛出异常是致命的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读