Application.Exit()

There is my code sample:

[STAThread]
static void Main() 
{
  Application.Run(new AppMain());
}

public AppMain()
{
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent();

  MyDataLoad MyData = new MyDataLoad();
  if(MyData.SerialNumber != "") {
    //do something...
  }
  else
    Application.Exit();
}

Why if MyData.SerialNumber is "" Application.Exit() is launched (traced on debugger), but has NO EFFECT with app closing  Application form is launched & I can perform on it, but at once I receive an error, cause some initialization in //do something has taken no place (rather obvious :) ).
Any tips, please  In MyDataLoad contructor I open some disk files, but I close it just after using it & I don't leave constructor with any opened files.


Answer this question

Application.Exit()

  • jerryload

    It works! Many thx  :)  
  • Keith Kiedrowski

    Instead of Application.Exit use Environment.Exit(0);
  • Application.Exit()