Click here to Skip to main content
15,903,012 members
Home / Discussions / C#
   

C#

 
GeneralRe: ObjectDisposedException Pin
George_George12-May-08 20:59
George_George12-May-08 20:59 
GeneralRe: ObjectDisposedException Pin
N a v a n e e t h13-May-08 2:19
N a v a n e e t h13-May-08 2:19 
GeneralRe: ObjectDisposedException Pin
George_George13-May-08 2:47
George_George13-May-08 2:47 
GeneralRe: ObjectDisposedException Pin
N a v a n e e t h13-May-08 18:53
N a v a n e e t h13-May-08 18:53 
GeneralRe: ObjectDisposedException Pin
George_George14-May-08 2:47
George_George14-May-08 2:47 
AnswerRe: ObjectDisposedException Pin
J4amieC12-May-08 2:23
J4amieC12-May-08 2:23 
GeneralRe: ObjectDisposedException Pin
George_George12-May-08 2:26
George_George12-May-08 2:26 
AnswerRe: ObjectDisposedException Pin
tgrt12-May-08 3:14
tgrt12-May-08 3:14 
I generally use the Disposing pattern which has sort of evolved from the IDisposable interface. The pattern when implemented looks like this in code:

    public class MyObject : IDisposable

    {

        ~MyObject()

        {

            Dispose(false);

        }

 

        public void Dispose()

        {

            Dispose(true);

            GC.SuppressFinalize(this);

        }

 

        private bool _disposed;   // indicates if Dispose has been called

 

        private void Dispose(bool disposing)

        {

            if (!_disposed)

            {

                if (disposing)

                {

                    // TODO: cleanup managed resources in MyObject

                }

 

                // TODO: cleanup unmanaged resources in MyObject

                _disposed = true;

            }

        }

    }



Once you have this pattern in place your methods can use something like this:

        public void SomeOperation()

        {

            if (_disposed)

                return;

 

            // TODO: do something

        }



Of course you're going to want to do something more meaningful then just return -- like throw your own exception or return an error code. It just depends on what you're doing that might call an object that has been disposed.
GeneralRe: ObjectDisposedException Pin
George_George12-May-08 18:45
George_George12-May-08 18:45 
QuestionMultiple schema Pin
PaulaM12-May-08 1:57
PaulaM12-May-08 1:57 
QuestionHow do use windows media player with multi threads?????????????????????????????????? Pin
Member 175177312-May-08 1:40
Member 175177312-May-08 1:40 
AnswerRe: How do use windows media player with multi threads?????????????????????????????????? Pin
N a v a n e e t h12-May-08 2:17
N a v a n e e t h12-May-08 2:17 
QuestionImplement Depth First Search Pin
Syed Ali Raza12-May-08 1:36
Syed Ali Raza12-May-08 1:36 
Questionsolve this error Pin
salil_k_singh12-May-08 1:20
salil_k_singh12-May-08 1:20 
AnswerRe: solve this error Pin
Anthony Mushrow12-May-08 1:26
professionalAnthony Mushrow12-May-08 1:26 
AnswerRe: solve this error Pin
ScottM112-May-08 1:34
ScottM112-May-08 1:34 
QuestionStrongName Question Pin
William Ten Broek12-May-08 1:20
William Ten Broek12-May-08 1:20 
AnswerRe: StrongName Question Pin
tgrt12-May-08 3:52
tgrt12-May-08 3:52 
GeneralRe: StrongName Question Pin
William Ten Broek12-May-08 10:24
William Ten Broek12-May-08 10:24 
QuestionFile attributes Pin
ScottM112-May-08 0:44
ScottM112-May-08 0:44 
AnswerRe: File attributes Pin
Anthony Mushrow12-May-08 1:28
professionalAnthony Mushrow12-May-08 1:28 
AnswerRe: File attributes Pin
Ashfield12-May-08 1:29
Ashfield12-May-08 1:29 
AnswerRe: File attributes Pin
MoustafaS12-May-08 2:28
MoustafaS12-May-08 2:28 
QuestionHelp with web services in C# Pin
WebMaster12-May-08 0:26
WebMaster12-May-08 0:26 
AnswerRe: Help with web services in C# Pin
Anthony Mushrow12-May-08 1:32
professionalAnthony Mushrow12-May-08 1:32 

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.