Click here to Skip to main content
15,896,154 members
Home / Discussions / C#
   

C#

 
GeneralRe: implement IDisposable issue Pin
leppie26-Nov-08 2:18
leppie26-Nov-08 2:18 
GeneralRe: implement IDisposable issue Pin
George_George26-Nov-08 2:25
George_George26-Nov-08 2:25 
GeneralRe: implement IDisposable issue Pin
leppie26-Nov-08 2:41
leppie26-Nov-08 2:41 
GeneralRe: implement IDisposable issue Pin
George_George26-Nov-08 3:16
George_George26-Nov-08 3:16 
GeneralRe: implement IDisposable issue Pin
leppie26-Nov-08 3:23
leppie26-Nov-08 3:23 
GeneralRe: implement IDisposable issue Pin
George_George26-Nov-08 3:31
George_George26-Nov-08 3:31 
AnswerRe: implement IDisposable issue Pin
Scott Dorman26-Nov-08 16:18
professionalScott Dorman26-Nov-08 16:18 
GeneralRe: implement IDisposable issue Pin
George_George26-Nov-08 20:58
George_George26-Nov-08 20:58 
Thanks Scott,

1.

"If so, then you generally don't need to do this" -- confused. Do you mean there is no need to call Dispose method in finalizer? If so, I disagree and in MSDN Dispose pattern, in finalizer dispose method is called with false value parameter.

2.

You mentioned "Normally static classes do not hold any internal state and would not actually need to do any object disposal of their own." -- confused. It is common to have a static class hold a member variable which pointed to disposable object instance, like stream. In your points, there is no need to dispose the wrapped disposable object instance?

3.

In my situation, the initialize method has to be static. Smile | :)

I have fixed some issues you mentioned and posted my new code below. Could you help to review whether my code is correct? Any potential issues?

class Logger : IDisposable
{
        private static bool disposed = false;
        private static StreamWriter  logStream;

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

        ~Logger()
        {
            Dispose(false);
        }

        private static void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (false == disposed)
            {
                // If disposing equals true, dispose all managed 
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    LogStream.Dispose();
                    LogStream = null;
                }
            }
            disposed = true;
        }

        public static void Uninitialize()
        {
            Dispose(true);
            GC.SuppressFinalize(l ogStream);
        }
}


regards,
George
GeneralRe: implement IDisposable issue Pin
Scott Dorman27-Nov-08 2:49
professionalScott Dorman27-Nov-08 2:49 
QuestionHow edit my URL on button click Pin
Exelioindia26-Nov-08 1:48
Exelioindia26-Nov-08 1:48 
AnswerRe: How edit my URL on button click Pin
Simon P Stevens26-Nov-08 1:56
Simon P Stevens26-Nov-08 1:56 
AnswerRe: How edit my URL on button click Pin
Dominic Goulet1-Dec-08 1:09
Dominic Goulet1-Dec-08 1:09 
QuestionExhange Server 2007 Webservice Pin
boiDev26-Nov-08 1:33
boiDev26-Nov-08 1:33 
Questioncopying files fast from 1 drive to other Pin
sumit703426-Nov-08 0:59
sumit703426-Nov-08 0:59 
AnswerRe: copying files fast from 1 drive to other Pin
Guffa26-Nov-08 1:14
Guffa26-Nov-08 1:14 
GeneralRe: copying files fast from 1 drive to other Pin
sumit703426-Nov-08 1:21
sumit703426-Nov-08 1:21 
AnswerRe: copying files fast from 1 drive to other Pin
Simon P Stevens26-Nov-08 1:16
Simon P Stevens26-Nov-08 1:16 
AnswerRe: copying files fast from 1 drive to other Pin
Shyam Bharath26-Nov-08 1:33
Shyam Bharath26-Nov-08 1:33 
Questionshowing a linklabel in a messagebox? Pin
lane0p226-Nov-08 0:53
lane0p226-Nov-08 0:53 
AnswerRe: showing a linklabel in a messagebox? Pin
Pedram Behroozi26-Nov-08 1:08
Pedram Behroozi26-Nov-08 1:08 
QuestionCode to find the csc.exe Pin
tonyjsebastian126-Nov-08 0:53
tonyjsebastian126-Nov-08 0:53 
AnswerRe: Code to find the csc.exe Pin
Shyam Bharath26-Nov-08 1:02
Shyam Bharath26-Nov-08 1:02 
AnswerRe: Code to find the csc.exe Pin
Pedram Behroozi26-Nov-08 1:02
Pedram Behroozi26-Nov-08 1:02 
AnswerRe: Code to find the csc.exe Pin
Mirko198026-Nov-08 2:15
Mirko198026-Nov-08 2:15 
GeneralRe: Code to find the csc.exe ======> U r correct Mikro1980 Pin
tonyjsebastian126-Nov-08 17:54
tonyjsebastian126-Nov-08 17:54 

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.