Look at the documentation:
WeakReference.Target Property (System)[
^]
And it states that:
Property Value
Type: System.Object
null if the object referenced by the current WeakReference object has been garbage collected; otherwise, a reference to the object referenced by the current WeakReference object.
Just because it is closed, does not mean that it has been deallocated by the Garbage Collector - remember that the garbage collector is only ever kicked into action when memory runs low
, or Dispose is called on an object. Closing a form does neither of those things, or you would not be able to access the content of a form once the user had finished filling it in and pressed "OK":
frmLogin f = new frmLogin();
if (f.ShowDialog() == DialogResult.OK)
{
string username = f.UserName;
...
}
If you want to know when a form is closed, you need to use the event, not a weak reference.
[edit]:doh: I need more caffeine...[/edit]