473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Windows Console App - how to terminate (abnormally)

Hi,

This may seem like a silly question but I'll ask anyway 8^)

I have a C# Windows "Console Application" that when a fatal error occurs,
I'll log the error and I then want to stop the program in its tracks ie.
terminate immeadiately.

Is there a call to do this eg. Application.Terminate ();
- peteZ
Nov 16 '05 #1
2 8705
Hi PeteZ,
Hi,

This may seem like a silly question but I'll ask anyway 8^)

I have a C# Windows "Console Application" that when a fatal error occurs,
I'll log the error and I then want to stop the program in its tracks ie.
terminate immeadiately.

Is there a call to do this eg. Application.Terminate ();
- peteZ


The best practise is to close application with normal
code process e.g.

formMain.Close() // in Windows application
or
return; // from Main() functions in console application.

But there are two other "fast" ways to close application:

1) Application.Exit();

2) create your own exception, e.g. MyExitException()
- throw it in wanted "exit" place
- catch it in Main(...) function e.g.:

public static void Main(string[] args) {
try {
// your application code
}
catch(MyExitException ) {
return;
}
}

Nov 16 '05 #2

"Marcin Grzêbski" <mg*******@taxussi.no.com.spam.pl> wrote in message
news:ca**********@atlantis.news.tpi.pl...
Hi PeteZ,
Hi,

This may seem like a silly question but I'll ask anyway 8^)

I have a C# Windows "Console Application" that when a fatal error occurs, I'll log the error and I then want to stop the program in its tracks ie.
terminate immeadiately.

Is there a call to do this eg. Application.Terminate ();
- peteZ


The best practise is to close application with normal
code process e.g.

formMain.Close() // in Windows application
or
return; // from Main() functions in console application.

But there are two other "fast" ways to close application:

1) Application.Exit();

2) create your own exception, e.g. MyExitException()
- throw it in wanted "exit" place
- catch it in Main(...) function e.g.:

public static void Main(string[] args) {
try {
// your application code
}
catch(MyExitException ) {
return;
}
}

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mike | last post by:
I want to create a windows service that will monitor another window service. what i need for the service to do is, if a service is stopped I need it to start the service back up example: ...
0
by: PeteZ | last post by:
Hi, This may seem like a silly question but I'll ask anyway 8^) I have a C# Windows "Console Application" that when a fatal error occurs, I'll log the error and I then want to stop the...
1
by: M D | last post by:
If you want more details you will have to reference the VS.Net example ConsoleChat for Networking How-to: -- http://go.microsoft.com/fwlink/?linkid=3480&path=/quickstart/howto/sampl...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
6
by: carbon_dragon | last post by:
Ok, so here is the problem. I'm working on a headless server program implemented as a .NET C# Console project. There is a UPS mounted to this server (though not a windows compliant UPS). I can only...
7
by: Frank | last post by:
Hi, I have a console app that I want to stop gracefully by another program. The console app already has code to intercept control-c and logoff and so on. But how do I send a control-c to that...
7
by: Daniel | last post by:
Hello! I am having a problem with a windows application that abnormally terminates itself. The application is a multi threaded .NET 1.1 application, and can briefly be described as follows: ...
3
by: Daniel Clark | last post by:
I have a Windows command line based application that only shuts down cleanly if it sees "CTRL-C" on the console. I need to automate the running of this application, but still allow the user sitting...
18
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.