473,785 Members | 2,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ter minate ();
- peteZ
Nov 16 '05 #1
2 8738
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.Ter minate ();
- 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.Exi t();

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(MyExitExc eption ) {
return;
}
}

Nov 16 '05 #2

"Marcin Grzębski" <mg*******@taxu ssi.no.com.spam .pl> wrote in message
news:ca******** **@atlantis.new s.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.Ter minate ();
- 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.Exi t();

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(MyExitExc eption ) {
return;
}
}

Nov 16 '05 #3

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

Similar topics

7
712
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: service 1 - my service watches service 2 - windows service service 2 is stopped - service 1 starts service 2
0
297
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 program in its tracks ie. terminate immeadiately. Is there a call to do this eg. Application.Terminate ();
1
1474
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 es/net/TCPUDP/Chat.src In trying to put it into a Windows form (c#.net, VS 2002) this is my main:
9
7273
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 stopping. Please advise how to stop the service. Thanks, SP
6
8766
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 talk to the UPS over a special device driver. Through this device driver I can detect that the UPS is going to notify Windows 2000 server to shut down. So I start doing a graceful termination. But Windows shuts down pretty quickly and there...
7
8421
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 console app from another program? The console application is started with a Process class. Thanks Frank
7
2598
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: Call the thread running the GUI "A". When user clicks a button a new thread "B" is created and started. "B" does a lots of work, among others transmitts data via a USB-CAN-interface. At the end of "B" a paper label is printed using methods provided...
3
9739
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 at the machine to cancel the process cleanly if he/she needs to. In Unix this would be a tiny shell script that used "kill -15", but under Windows there does not seem to be an easy way to do this, at least that I can find. Below is a test...
18
14655
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.