In this article, we will be discussing about the proper way for closing a C# application (including hidden forms).
C# Applications with Multiple Forms
There are many times when we develop C# applications, where we make use of several forms. To this end, there are times that we are using the Hide() method for some of these forms thus hiding the forms, but not closing or disposing them.
Nevertheless, in the main form of a program we usually make use of an “Exit” button or another similar control. If the even code used behind this control calls the form to be closed or disposed, the application still runs due to the other hidden forms.
How to Properly Close a C# Application
In order to totally close a C# application, including the hidden forms, you can use the following command in the event code of the “Exit” control:
Application.Exit();
Get Started with .NET Programming Fast and Easy – Enroll to the Course!
Check our online course titled “.NET Programming for Beginners – Windows Forms with C#” (special limited-time discount included in link).
Learn how to implement Windows Forms projects in .NET using Visual Studio and C#, how to implement multithreading, how to create deployment packages and installers for your .NET Windows Forms apps using ClickOnce in Visual Studio, and more!
Many live demonstrations and downloadable resources included!
Recommended Online Courses:
- SQL Server 2022: What’s New – New and Enhanced Features
- Data Management for Beginners – Main Principles
- Introduction to Azure Database for MySQL
- Working with Python on Windows and SQL Server Databases
- Boost SQL Server Database Performance with In-Memory OLTP
- Introduction to Azure SQL Database for Beginners
- Essential SQL Server Administration Tips
- SQL Server Fundamentals – SQL Database for Beginners
- Essential SQL Server Development Tips for SQL Developers
- Introduction to Computer Programming for Beginners
- .NET Programming for Beginners – Windows Forms with C#
- SQL Server 2019: What’s New – New and Enhanced Features
- Entity Framework: Getting Started – Complete Beginners Guide
- A Guide on How to Start and Monetize a Successful Blog
- Data Management for Beginners – Main Principles
Read Also:
- How to Set Filters for OpenFileDialog and SaveFileDialog in C#
- There is no argument given that corresponds to the required formal parameter
- How to Establish a Simple Connection from a C# Program to SQL Server
- The timeout period elapsed prior to obtaining a connection from the pool
- Changing the startup form in a C# project
- Using the C# SqlParameter Object for Writing More Secure Code
- Cannot implicitly convert type ‘string’ to ‘System.Windows.Forms.DataGridViewTextBoxColumn
- The type or namespace name ‘Office’ does not exist in the namespace ‘Microsoft’ – How to Resolve
- Using the C# SqlParameter Object for Writing More Secure Code
- Tip of the Week No.15 – Main Data Structures in C#
Did you find this article useful and interesting?
Interested in SQL Server Administration? Find hundreds of useful SQL Server administration and troubleshooting articles in 9 Times Microsoft Data Platform MVP, Artemakis’ Artemiou eBook: “Administering SQL Server (Second Edition)“.
Check our other related .NET articles.
Check out our latest software releases!
Subscribe to our newsletter and stay up to date!
Rate this article:
Reference: SQLNetHub.com (https://www.sqlnethub.com)
© SQLNetHub
Artemakis Artemiou, a distinguished Senior Database and Software Architect, brings over 20 years of expertise to the IT industry. A Certified Database, Cloud, and AI professional, he earned the Microsoft Data Platform MVP title for nine consecutive years (2009-2018). As the founder of SQLNetHub and GnoelixiAI Hub, Artemakis is dedicated to sharing his knowledge and democratizing education on various fields such as: Databases, Cloud, AI, and Software Development. His commitment to simplicity and knowledge sharing defines his impactful presence in the tech community.