5 Replies - 7348 Views - Last Post: 06 August 2011 - 01:18 PM Rate Topic: -----

#1 AVReidy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 65
  • View blog
  • Posts: 431
  • Joined: 17-February 11

How do I terminate a C# program?

Posted 06 August 2011 - 12:53 PM

What is the C# equivalent to Java's System.exit(0);?
Is This A Good Question/Topic? 0
  • +

Replies To: How do I terminate a C# program?

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: How do I terminate a C# program?

Posted 06 August 2011 - 12:57 PM

I don't know if it is equal to the Java call you mentioned, but to terminate a C# program you either close the main form or can call

Application.Exit();


Personally I would suggest you close the main form. That way you can react to the .Closing event to clean up any resources, ask the user to confirm they want to close the application, save any changed settings/preferences, save any open documents and other tidy-ing up and housekeeping you might have.
Was This Post Helpful? 1
  • +
  • -

#3 CodingSup3rnatur@l-360  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 991
  • View blog
  • Posts: 971
  • Joined: 30-September 10

Re: How do I terminate a C# program?

Posted 06 August 2011 - 01:02 PM

Hi,

I would say that Environment.Exit(0); is the closest to Java's System.exit(0);.

See here.

This post has been edited by CodingSup3rnatur@l-360: 06 August 2011 - 01:02 PM

Was This Post Helpful? 2
  • +
  • -

#4 AVReidy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 65
  • View blog
  • Posts: 431
  • Joined: 17-February 11

Re: How do I terminate a C# program?

Posted 06 August 2011 - 01:09 PM

Thank you all.
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: How do I terminate a C# program?

Posted 06 August 2011 - 01:13 PM

Now I'm curious. In real-world uses how is that different than telling your application to .exit()?

And for answering the title question

Quote

How Do I Terminate A C# Program?


I would think Application.Exit() to be a better choice. Or do you know an advantage with Environment.Exit()?
Was This Post Helpful? 0
  • +
  • -

#6 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: How do I terminate a C# program?

Posted 06 August 2011 - 01:18 PM

Environment.Exit allows you to return a value so you can indicate something about the processing (like to a batch file).
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1