Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start VB.NET GUI app using Sub Main or form startup object?

Is there any reason to start a GUI program (application for Windows) written in VB.NET in the Sub Main of a module rather than directly in a form?

EDIT: The program won't take any command line parameters and it will be executed as a GUI program always.

like image 362
ggf31416 Avatar asked Nov 22 '08 13:11

ggf31416


People also ask

What is the starting point for a VB NET application?

Every Visual Basic application must contain a procedure called Main . This procedure serves as the starting point and overall control for your application. The . NET Framework calls your Main procedure when it has loaded your application and is ready to pass control to it.

How do I change the startup form in Visual Studio 2019?

1) Double-click on My Project under the project in Solution Explorer. 2) Click the Application tab. 3) Set the Startup form.


1 Answers

The primary reason for using Main() in VB .NET 1.x was for adding code that needed to run before any forms were loaded. For example, you might want to detect whether an instance of your Windows Forms app was already loaded. Or you might want to intercept any unhandled exception for the AppDomain:

AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf MyExceptionFilter

But the next version of VB and Visual Studio 2005 introduced a new Application model that made Main() unnecessary in most scenarios. You can now intercept the My.Application.Startup event to add code that needs to run before any forms are loaded.

Note that the code for the Startup event handler is stored in the ApplicationEvents.vb file, which is hidden by default.

like image 61
HTTP 410 Avatar answered Sep 20 '22 16:09

HTTP 410