Answer the question
In order to leave comments, you need to log in
How to terminate a winforms application?
Hello.
I have a c# winforms application. All the necessary code is executed by functions even before the form itself is loaded (in theory), it looks like this:
public Form1()
{
this.Opacity = 0;
this.ShowInTaskbar = false;
this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
doit();
}
Answer the question
In order to leave comments, you need to log in
Remove all code associated with the form. Make the initialization method static. Specify the type "console application" in the project settings, and the initialization method as the entry point.
If Application.Exit crashes, then look at the FormClosing event. Apparently something is being done in it, but in general, run it in debug mode and show the full error.
PS: As a crutch, you can use Environment.Exit(0);
public Form1()
{
InitializeComponent();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question