469,349 Members | 1,624 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,349 developers. It's quick & easy.

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 47861
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Guinness Mann | last post: by
11 posts views Thread by Peter Steele | last post: by
4 posts views Thread by Bob Day | last post: by
4 posts views Thread by JIM.H. | last post: by
1 post views Thread by =?Utf-8?B?VGFvZ2U=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.