Link to home
Start Free TrialLog in
Avatar of Andrew Werber
Andrew Werber

asked on

Error trying to close main form in Windows Form project

After creating a Windows Form project I added Close(); after InitializeComponent(); in the constructor. When I run the project, i get the following error:

Make sure you have not released a resource before attempting to use it

The error happens in the Program.cs file.

My real code at work is a bit more complicated, what I'm doing is authenticating a user against a table and then trying to close to form if they're not in the table. But the functions I call are called from the constructor, and the error is the same error in the same place. I'd like to know how to close the form from the constructor, other than sinking the error. I'm concerned that there may be a memory leak.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can check that before you call the constructor of the form.  Or the other option is to create a "Blackout Panel" (EG: a fully docked panel) and set that visible to true if they aren't authenticated / authorized.
Avatar of Andrew Werber
Andrew Werber


Since this was the first answer, I tried it and it worked. Thanks!