Gorgo.Live.ToString()

Mariusz, Gorzoch tech Blog

Archive for September 2009

Proper construction of classes which need to release they child objects

leave a comment »

Each time when I need to write a class which need to work with some COM objects I reinvent the wheel be finding out what should be a proper construction class. This time I wanted to put this in one place so I’ll have reference to that. Ok, so what is the proper class construction ? Take look here:

class Test : IDisposable
{
    #region IDisposable Members

    public void Dispose()
    {
        GC.SuppressFinalize(this);

        CleanUp(true);
    }

    #endregion

    private void CleanUp(bool codeDispose)
    {
        if (codeDispose)
        {
            //dispose called in code not by GC
        }

        //Perform resource clean-up here
        // for example relese you all COM Objects
    }

    ~Test()
    {
        CleanUp(false);
    }
}

This construction have to ways of releasing objects. First one is “Dispose” mechanism. If developer will use disposal method to release object resources then those resources will be released when he want. Second one is done thru destructor of the class. Inside destructor we are calling “CleanUp” method and by this releasing object. Someone can ask what for we need “Dispose” mechanism if destructor way do not depend on the developer and also is doing his job. The answer is simple : in case of the “Destructor” we are rallying on special “Thread” use by .Net to call our destructor. In addition to that, we need to know that this special Thread will call our destructor method when GC will perform his clean-up work and move our object to higher generation. This process consume much more resources then the one with use of “Dispose” method, so whatever you can use “Dispose” mechanism.

here is some reference, which is quite good overview of the problem : http://www.red-gate.com/products/ants_memory_profiler/DOTNET_Memory_Management/Index.html

Advertisements

Written by Mariusz Gorzoch

29 September 2009 at 09:58

Posted in Bez kategorii

How nicely tell users that our app is under maintenance

leave a comment »

Did you ever fight with this issue ? Did you boss ever ask you if you can do something about this strange 404 Error : Page not found, when you are upgrading you application to new version ? Here I have solution for you. I discovered this today, when I was publishing my asp.net app from visual studio. During publish time I pressed in the browser refresh button and then get a strange info “Page is unavailable, please remove “app_offline.htm” file from root directory”. I say… woow… 🙂 So, the answer on this request from your boss, mom, or whoever is simply put “app_offline.html” file to root directory of you app and this will let IIS to redirect all request from the user to this file. During this time you can do whatever you want with your app and no one will disturb you.

Take a look:

1. IIS without “app_offline.htm” file

2. After adding file to root directory of the site and restarting IIS

in addition, what I really like about it is, that it doesn’t meter what you type inside query string as long it point to you IIS app. All files requested by the user are redirected to this particular html file, for example:

http://mgodevstation:8080 – redirected to –> http://mgodevstation:8080/app_offline.html

http://mgodevstation:8080/default.aspx – redirected to –> http://mgodevstation:8080/app_offline.html

http://mgodevstation:8080/blablablablablababla.aspx  – redirected to –> http://mgodevstation:8080/app_offline.html

Hope that upgrade of your app will be nicer next time.

Written by Mariusz Gorzoch

15 September 2009 at 10:01

Posted in Bez kategorii