none
checking if a control still exists RRS feed

  • Question

  • hi

    i have a variable of type user control:

    Control ^mycontrol; somewhere in my code i write:

    mycontrol->~mycontrol;

    somewhere else in the code i want to check if the control still exists could someone please tell how this can be done??

    any help would be most appreciated.
    Wednesday, August 26, 2009 3:15 PM

Answers

  • You can use the mycontrol->IsDisposed property.

    Hans Passant.
    • Marked as answer by Wesley Yao Tuesday, September 1, 2009 3:32 AM
    Wednesday, August 26, 2009 4:28 PM
    Moderator
  • I don't know what "doesn't always work" means.  The destructor sets the IsDisposed property.  A control disposing itself is pretty unusual, it should be the client of the control that disposes it.  Only that client can know whether or not the control is still in use.  Disposing is done automatically the vast majority of the time, done by the Form class when it closes.  Disposing when you shouldn't produces ObjectDisposedException.

    Hans Passant.
    • Marked as answer by Wesley Yao Tuesday, September 1, 2009 3:32 AM
    Thursday, August 27, 2009 10:30 AM
    Moderator

All replies

  • You can use the mycontrol->IsDisposed property.

    Hans Passant.
    • Marked as answer by Wesley Yao Tuesday, September 1, 2009 3:32 AM
    Wednesday, August 26, 2009 4:28 PM
    Moderator
  • You can use the mycontrol->IsDisposed property.

    Hans Passant.
    I've done that but it doesn't always work properly. Do I need to set the IsDisposed property??
    I must add that its not:

    mycontrol->~mycontrol;

    its:

    this->~Control();

    I call the destructor in the control itself.
    Thursday, August 27, 2009 5:47 AM
  • I don't know what "doesn't always work" means.  The destructor sets the IsDisposed property.  A control disposing itself is pretty unusual, it should be the client of the control that disposes it.  Only that client can know whether or not the control is still in use.  Disposing is done automatically the vast majority of the time, done by the Form class when it closes.  Disposing when you shouldn't produces ObjectDisposedException.

    Hans Passant.
    • Marked as answer by Wesley Yao Tuesday, September 1, 2009 3:32 AM
    Thursday, August 27, 2009 10:30 AM
    Moderator