Blue Theme Orange Theme Green Theme Red Theme
 
DevExpress Free UI Controls
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
DevExpress UI Controls
Search :       Advanced Search »
Home » Windows Forms » Start and Close a Windows Application in VB.NET

Start and Close a Windows Application in VB.NET

Application class provides Run and Exit static methods that can be used to start and close a Windows Forms applcation. This article discusses these methods, their roles and how to use them.

Author Rank :
Page Views : 5014
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
DevExpress Free UI Controls
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Run and Exit

Every Windows Forms application must have a main thread also known as primary thread that is executed when an application starts. An execution thread is a path of execution of code in an application. The main thread of an application starts by calling the Main method of an application. In .NET 4.0, the main thread is also called main message loop.

A Windows application may have at least one or more threads. Running multiple threads in a single application is also known as multi-threading. We discuss multi-threading in more details in the Threads and Processes chapter.

The entry point of a Windows application is run and ending point is close. In between run and exit, an application catches and handles Windows events occurred by accepting input devices as mouse clicks and keyboard strokes. The main message loop handles all the messages.

The Application class provides a Run method that starts an application. If you look at the Program.cs class in a Windows Forms application created by Visual Studio 2010, you will notice a Main method as listed in Listing 9.

static class Program

{

    /// <summary>

    /// The main entry point for the application.

    /// </summary>

    [STAThread]

    static void Main()

    {

        Application.EnableVisualStyles();

        Application.SetCompatibleTextRenderingDefault(false);

        Application.Run(new Form1());

    }

}

Listing 9

If you need to change the startup form of a Windows Forms application, you need to pass an instance of that Form class in the Application.Run method. Let's say, you have a Form called MasterForm and would like to open this form when application starts. To do so, you need to change the Application.Run() method call in Listing 9 to the following: 

        Application.Run(new MasterForm())

 

The following code snippet is VB.NET version of calling the Run method.

 

Application.Exit() method is used to close an application. This method notifies Windows that all messages for the current application must be terminated and all windows must be closed. You can use this method to close the application such as on Exit menu or Close button event handler.

 

        Application.Exit();

The following code snippet is VB.NET version of calling the Exit method.

 

        Application.Exit()


Summary

Programming Windows Forms using Visual Basic 2010 is a programming guide for Windows Forms developers using Visual Basic 2010 and Visual Studio 2010. This is an ongoing series. In this part, we learned about the Run and Exit methods of the Application class and how they are used in an application.

 

Programming Windows Forms using Visual Basic 2010

Here are previous articles related to this series.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Mahesh Chand
Mahesh is the founder of C# Corner and Mindcracker Network, an author of several .NET programming books and a Microsoft MVP for 6 consecutive years. In his day to day work, Mahesh is a Senior Software Consultant with over 14 years of IT industry experience building systems for Financial and Banking, Engineering & Architectural, Imaging, Construction, Biological & Pharmaceuticals, Healthcare and Education industries. His expertise is Windows Forms, ASP.NET, Silverlight, WPF, WCF, Visual Studio 2010, SQL Server, and Oracle.  If you are looking for a Sharepoint, Windows Forms, ASP.NET, WPF, Silverlight, C#, VB.NET, Oracle, and SQL Server Consultant in Philadelphia area or remote location, drop me a line at MAHESH [AT] C-SHARPCORNER [DOT] COM.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Comments

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.