0

I have found that it seems to be, but i do not understand the internal workings of this property to know for sure. When the user closes the form, this property seems to reliably return False.

I use this when i have background workers running, and i check this property in the completed event before doing any further processing.

Luke
  • 69
  • 1
  • 4
  • 1
    Not exactly, it is also False when the window wasn't yet created. You only *really* care about IsDisposed. Check [this answer](http://stackoverflow.com/questions/1731384/how-to-stop-backgroundworker-on-forms-closing-event/1732361#1732361) – Hans Passant Aug 12 '13 at 00:07
  • Hans, background processes in my application are only ever kicked off as a result of a user clicking a button so there would be no way that i would ever be checking this property before the form was created. If i try and invoke methods on my form from a background worker and the form is closed (but not yet disposed) is "Invoke or BeginInvoke cannot be called on a control until the window handle has been created.". Checking ishandlecreated works perfectly in that situation where me.isdisposed does not – Luke Aug 13 '13 at 23:05

1 Answers1

0

I wouldn't use that. Agreeing with Hans Passant, I would use Me.IsDisposed because that will check to make sure that it was open and then shut down and disposed the memory.

nick
  • 425
  • 2
  • 4
  • 10
  • The problem with Me.IsDisposed is that it returns true after the form is closed. It doesnt get disposed instantly after, only after garbage collection right? – Luke Aug 13 '13 at 23:02
  • "When this property returns true, the control is disposed of and can no longer be referenced as a valid Windows control. Even though the instance of a control is disposed of, it is still maintained in memory until it is removed from memory through garbage collection." -MSDN – nick Aug 15 '13 at 14:02