Click here to Skip to main content
15,888,527 members

Tim Abell - Professional Profile



Summary

    Blog RSS
12
Debator
1
Enquirer
6
Organiser
132
Participant
0
Author
0
Authority
0
Editor
This member doesn't quite have enough reputation to be able to display their biography and homepage.

Reputation

Weekly Data. Recent events may not appear immediately. For information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilver
Bypass spam checks when posting contentsilversilversilversilversilversilvergoldSubEditor, Mentor, Protector, Editor
Store personal files in your account areaplatinumplatinumSubEditor, Editor
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Edit a Question in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Edit an Answer in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Delete a Question in Q&AYesSubEditor, Protector, Editor
Delete an Answer in Q&AYesSubEditor, Protector, Editor
Report an ArticlesilversilversilversilverSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubEditor, Mentor, Protector, Editor
Edit other members' articlesSubEditor, Protector, Editor
Create an article without requiring moderationplatinumSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending QuestionProtector
Approve/Disapprove a pending AnswerProtector
Report a forum messagesilversilverbronzeProtector, Editor
Approve/Disapprove a pending Forum MessageProtector
Have the ability to send direct emails to members in the forumsProtector
Create a new tagsilversilversilversilver
Modify a tagsilversilversilversilver

Actions with a green tick can be performed by this member.


 
GeneralImplementing IDisposeable in C# Pin
Tim Abell11-Jan-06 5:53
Tim Abell11-Jan-06 5:53 
Implement IDisposeable if you use "expensive" resources eg database connections.
I wrote this to help me understand how dispose is used and how it affects execution.

It's a basic console app (for .NET 2.0) and can be compiled with csc.exe

Here's the code:
using System;
public class hellodispose
{
    public static void Main()
    {
        Console.WriteLine();
        Console.WriteLine("test with dispose");
        Console.WriteLine("=================");
        Test(true);
        Console.WriteLine("====================");     
        Console.WriteLine();
        Console.WriteLine("test without dispose");
        Console.WriteLine("====================");
        Test(false);
        Console.WriteLine("====================");
    }

    private static void Test(bool rundispose)
    {
        Console.WriteLine("main()");
        Console.WriteLine("create dt:");
        disposetest dt = new disposetest(rundispose?1:0);
        Console.WriteLine("optionally call dispose:");
        if (rundispose) dt.Dispose();
        Console.WriteLine("end");
    }

    public class disposetest : IDisposable
    {
        private int _instance;
        public disposetest(int instance)
        {
            _instance = instance;
            Console.WriteLine("disposetest({0})", _instance);
        }
        ~disposetest()
        {
            Console.WriteLine("~disposetest({0})", _instance);
            Console.WriteLine("- force dispose: ({0})", _instance);
            Dispose();
        }

        public void Dispose()
        {
            Console.WriteLine("Dispose() ({0})", _instance);
           GC.SuppressFinalize(this); //try commenting this out - note dispose is called in the destructor even id it was called by the owner code.
        }
    }
}


And here's the output:
test with dispose
=================
main()
create dt:
disposetest(1)
optionally call dispose:
Dispose() (1)
end
====================

test without dispose
====================
main()
create dt:
disposetest(0)
optionally call dispose:
end
====================
~disposetest(0)
- force dispose: (0)
Dispose() (0)


and with the GC.SuppressFinalize(this) statement removed:

test with dispose
=================
main()
create dt:
disposetest(1)
optionally call dispose:
Dispose() (1)
end
====================

test without dispose
====================
main()
create dt:
disposetest(0)
optionally call dispose:
end
====================
~disposetest(0)
- force dispose: (0)
Dispose() (0)
~disposetest(1)
- force dispose: (1)
Dispose() (1)


The upshot of this as far as I'm concerned is:
- The IDisposable interface makes it clear the class uses expensive resources.
- Dispose() allows the consumer of a class to release the expensive resources immediately.
- The destructor should release the expensive resources, but only if they have not already been released, and using the GC.SuppressFinalize routine allows dispose to prevent the destructor from re-running the Dispose() routine.

Note that garbage collection is a separate thread, which is why the destructors fire outside the main routine.

References:

Programming for Garbage Collection
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconProgrammingEssentialsForGarbageCollection.asp

Implementing a Dispose Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconimplementingdisposemethod.asp?frame=true&hidetoc=true

IDisposable Interface
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemidisposableclasstopic.asp

IDisposable.Dispose Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemIDisposableClassDisposeTopic.asp?frame=true&hidetoc=true

The IDisposable design pattern considered harmful
http://www.vbinfozine.com/a_disposable.shtml

Fundamentals of IDisposable (and some best practices)
http://www.codeproject.com/dotnet/ForDotNetBeginner.asp
GeneralChanging the title of MasterPage from the code of a templated page. Pin
Tim Abell11-Jan-06 3:36
Tim Abell11-Jan-06 3:36 
GeneralHandling "A potentially dangerous Request.Form value was detected" Pin
Tim Abell9-Nov-05 5:07
Tim Abell9-Nov-05 5:07 
Generalvisual studio dataset xml / insert with autoincrement Pin
Tim Abell10-Aug-05 6:03
Tim Abell10-Aug-05 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.