473,406 Members | 2,549 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,406 software developers and data experts.

Exit an Application

I have a form, which is getting some settings from the
App.config in the form load. If the Key doesn't exist, I
need to close the application after trapping the error.

I tried Application.Exit() and Form.Close() neither seems
to be the right one.

Thanks,

Rajesh Abraham Chacko
Nov 15 '05 #1
4 48030
Rajesh,

The location of the Application.Exit() is crucial in this working. Can you
provide more information about just what functions perform your config read,
and how you are trying to trap this...perhaps provide a complete code sample
that fails?
--
John Wiese
---
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Rajesh Abraham" <ch******@hotmail.com> wrote in message
news:0a****************************@phx.gbl...
I have a form, which is getting some settings from the
App.config in the form load. If the Key doesn't exist, I
need to close the application after trapping the error.

I tried Application.Exit() and Form.Close() neither seems
to be the right one.

Thanks,

Rajesh Abraham Chacko

Nov 15 '05 #2
Rajesh,

The location of the Application.Exit() is crucial in this working. Can you
provide more information about just what functions perform your config read,
and how you are trying to trap this...perhaps provide a complete code sample
that fails?
--
John Wiese
---
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Nov 15 '05 #3
Thanks for the response. Below is the code from a Helper
function that is called from the Form Load. The Helper is
just getting the DefaultSchoolName from the App.config. If
it could not get the value then Combos
cmbSchool.SelectedIndex will be -1, in which case I would
like to terminate the Application

Thanks,

Rajesh Abraham Chacko

-----------------------Code Below--------------

System.Configuration.AppSettingsReader appReader =new
System.Configuration.AppSettingsReader();
string defaultSchoolName=
appReader.GetValue "ImportToAd.DefaultSchoolName",typeof
(System.String)).ToString();
cmbSchool.SelectedIndex=cmbSchool.FindStringExact
(defaultSchoolName);

if (cmbSchool.SelectedIndex== -1)
{
MessageBox.Show("Failed to Get the Default School Name");
this.Close();
}
Nov 15 '05 #4
If you call this.Close() or Application.Exit() on a form in the contructor,
it won't close. If this form is the main form in your application, trying
loading your config settings in your Main() function, before you call
Application.Run(). Then, if you can't find the key, just don't call
Application.Run() and let your program finish before the form is ever
instantiated.

Chris
"Rajesh Abraham" <ch******@hotmail.com> wrote in message
news:0a****************************@phx.gbl...
I have a form, which is getting some settings from the
App.config in the form load. If the Key doesn't exist, I
need to close the application after trapping the error.

I tried Application.Exit() and Form.Close() neither seems
to be the right one.

Thanks,

Rajesh Abraham Chacko

Nov 15 '05 #5

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

Similar topics

1
by: Guinness Mann | last post by:
Pardon me if this is not the optimum newsgroup for this post, but it's the only .NET newsgroup I read and I'm certain someone here can help me. I have a C# program that checks for an error...
1
by: Brendan Miller | last post by:
I am trying to close my application using Application.exit() in the frmMain_Closing event. When the form closes the process does not. My application only has one form (no other classes either). ...
11
by: Peter Steele | last post by:
I have a Windows application written in C# that I want to return a non-zero exit code when it it run. The problem is that as a Windows application, there doesn't seem to be a way to control this....
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
1
by: Ioannis Vranos | last post by:
I am currently reading a chapter involving multithreading, and some sample code calls Environment::Exit() to terminate the application with all threads. What is the difference from...
4
by: Bob Day | last post by:
Using VS 2003, VB.net... I am confused about the Application.Exit method, where the help states "This method does not force the application to exit." Aside from the naming confusion, how do I...
8
by: Zeno Lee | last post by:
What is the best way to return an exit code from a VB.NET windows forms app? My Forms application is dual purpose. It is an interactive windows app. It is also automated and run via a script and...
4
by: JIM.H. | last post by:
Here is the code I am having problem: static void Main(string args) { bool isPar = false; if ((args.Length == 1)) { if ((args(0).ToUpper() == "MYPAR")) { isPar = true;
1
by: =?Utf-8?B?VGFvZ2U=?= | last post by:
Hi All, When I use applcation.exit() in winForm application, the form closed, but the process is still going!! ( The debug process is still running if debug in VS IDE). Environment.Exit(0) works...
2
by: Bassem | last post by:
I'm working on simple chat program via serial port. It works fine, but i face this problem. When i try to open the exe, UnauthorizedAccess exception occurs, i can't use COM1 becuase someone else has...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.