Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# interview question

Tags:

c#

asp.net

This is an interview question I need help with.

You have the following ASP.NET code-behind class:

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;      
    }
}

Any time someone requests this page, the w3wp.exe process terminates unexpectedly.

  • Why does this occur versus the user seeing a yellow screen of death (default ASP.NET error page)?

  • Why is there always an OutOfMemoryException present on the managed heap?

like image 226
user699046 Avatar asked Apr 08 '11 16:04

user699046


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Why is C named so?

Quote from wikipedia: "A successor to the programming language B, C was originally developed at Bell Labs by Dennis Ritchie between 1972 and 1973 to construct utilities running on Unix." The creators want that everyone "see" his language. So he named it "C".

What is C language?

C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community. Many versions of UNIX-based operating systems are written in C.


1 Answers

Hint: never throw exceptions in a destructor/finalizer or you will kill the thread on which the GC runs and without GC things might get ugly.

While there was some tolerance in .NET 1.1 towards exceptions thrown in background threads which were consumed and wouldn't bring the hosting process down that's no longer the case starting from 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.

Throwing an exception in a finalizer is fatal.

like image 175
Darin Dimitrov Avatar answered Sep 30 '22 18:09

Darin Dimitrov