Exiting program

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi folks,

I have a simple form like this:

public class Blah: System.Windows.Forms.Form{
private OleDBConnection conn;
public class Blah(){
conn.ConnectionString = "... ....";
try{
conn.open();
}
catch(Exception e){
Application.Exit(); <--- does not work
}
}

static void Main(){
Application.run(new Blar());
}
}

Problem:
1. When system fails to connection to SQL server, it catchs error and
executes Application.Exit(). But it does not work! After this line, it still
pops up the form.

Question:
1. How to terminate program properly when something goes wrong during system
loading?

Thanks,

Karl
 
Calling Application.Exit only sends a message that it wants to shutdown, but
you must exit the procedure before it will actually shutdown. Just type
return; so that it exits the procedure after the Application.Exit
 
Back
Top