471,327 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Quick Question on Application.Exit()

In C# 2.0, w/ the Program.cs file, i noticed that the Application.Run(new
appname()) is run twice. I have in my constructor to do a check for a
settings file, and if it isn't found, the application exits. But the app
doesn't exit, can someone tell me what i'm doing wrong?

here's my code:
if (filename == null)

Application.Exit();
Nov 29 '05 #1
5 2344
Doug,

There is no reason why the static Run method on the Application class
should be run twice. That's a definite error. I would remove the one after
the initial call, and then see what happens.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Doug Handler" <dk*******@yahoo.com> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
In C# 2.0, w/ the Program.cs file, i noticed that the Application.Run(new
appname()) is run twice. I have in my constructor to do a check for a
settings file, and if it isn't found, the application exits. But the app
doesn't exit, can someone tell me what i'm doing wrong?

here's my code:
if (filename == null)

Application.Exit();

Nov 29 '05 #2
"Doug Handler" <dk*******@yahoo.com> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
In C# 2.0, w/ the Program.cs file, i noticed that the Application.Run(new
appname()) is run twice. I have in my constructor to do a check for a
settings file, and if it isn't found, the application exits. But the app
doesn't exit, can someone tell me what i'm doing wrong?

here's my code:
if (filename == null)

Application.Exit();


Are you sure your logic makes sense? Above you say "if it isn't found", but
this code doesn't check for the existance of a file, only that the filename
variable isn't null. Are you meaning to do something like:

if (!File.Exists(filename))
{
Application.Exit();
}

?
Nov 29 '05 #3

"Doug Handler" <dk*******@yahoo.com> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
In C# 2.0, w/ the Program.cs file, i noticed that the Application.Run(new
appname()) is run twice. I have in my constructor to do a check for a
settings file, and if it isn't found, the application exits. But the app
doesn't exit, can someone tell me what i'm doing wrong?

here's my code:
if (filename == null)

Application.Exit();

How sure are you that filename is really null? I ask because a quick test
using a String explicitly set to null allows Application.Exit() to be called
and results in the expected termination here.
Have you walked through the code in the debugger to see the value assigned
to filename?
Note also that "" appears not to be equivalent to null. If I assign: String
s = ""; then testing if(s == null) returns false.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 29 '05 #4
Nicholas,

I didn't add the extra one. Create a simple winform project and go into the
Program.cs file and put a breakpoint. Then in the constructor of the main
form, (after the InitializeComponent() ) do something like call
messagebox.show. after that line put the Application.exit. See if it runs
"twice".

Doug
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uu**************@TK2MSFTNGP10.phx.gbl...
Doug,

There is no reason why the static Run method on the Application class
should be run twice. That's a definite error. I would remove the one
after the initial call, and then see what happens.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Doug Handler" <dk*******@yahoo.com> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
In C# 2.0, w/ the Program.cs file, i noticed that the Application.Run(new
appname()) is run twice. I have in my constructor to do a check for a
settings file, and if it isn't found, the application exits. But the app
doesn't exit, can someone tell me what i'm doing wrong?

here's my code:
if (filename == null)

Application.Exit();


Nov 29 '05 #5
Regarding my code below, i'm 100% positive its null. My issue isn't w/ the
code below, I know it executes fine. BTW, in a different class filename is
set to null if it isn't found for design purpose. My concern is that for
whatever reason, when i put the logic to exit the application, the
Application.Run statement in the Program.cs is executed twice. I know this
by the fact i put a breakpoint on it. Try it - see my previous posting.

I'm going to assume that you don't have an answer.

dh
"Danny Tuppeny" <gr****@dannytuppeny.commmmmm> wrote in message
news:43***********************@ptn-nntp-reader04.plus.net...
"Doug Handler" <dk*******@yahoo.com> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
In C# 2.0, w/ the Program.cs file, i noticed that the Application.Run(new
appname()) is run twice. I have in my constructor to do a check for a
settings file, and if it isn't found, the application exits. But the app
doesn't exit, can someone tell me what i'm doing wrong?

here's my code:
if (filename == null)

Application.Exit();


Are you sure your logic makes sense? Above you say "if it isn't found",
but this code doesn't check for the existance of a file, only that the
filename variable isn't null. Are you meaning to do something like:

if (!File.Exists(filename))
{
Application.Exit();
}

?

Nov 29 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Guinness Mann | last post: by
4 posts views Thread by Bob Day | last post: by
3 posts views Thread by Marcel Saucier | last post: by
7 posts views Thread by Jay | last post: by
1 post views Thread by =?Utf-8?B?VGFvZ2U=?= | last post: by

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.