Check if class has been instantiated

Posted by Holman716 on Stack Overflow See other posts from Stack Overflow or by Holman716
Published on 2010-05-28T20:24:42Z Indexed on 2010/05/28 20:32 UTC
Read the original article Hit count: 100

Filed under:

In my current program I have a main window and a secondary window that pops up when a button is pressed. If the secondary window is currently shown but doesn't have focus the button will instead bring it to focus.

At this time I am creating a new instance of the secondary window as the main window loads and simply checking its status with SubWindow.IsDisposed and SubWindow.CanFocus

I have found that if I do not create a new instance at the beginning SubWindow.IsDisposed throws an exception. As long as I'd previously created an instance of SubWindow the check runs fine.

My question- The current version works fine but is there a better way of doing this? It is not a huge concern, but it feels like it'd be better to be able to check for existence without having to guarantee that it has existed at least once before.

© Stack Overflow or respective owner

Related posts about c#