473,372 Members | 1,015 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,372 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 2454
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 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). ...
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...
20
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in...
3
by: Marcel Saucier | last post by:
I have written a Console Application then created a shortcut to it on my desktop. I was able to minimize the DOS window when I click my shortcut so I dont see anymore the DOS window But, using...
7
by: Jay | last post by:
In my C# code, I'm attempting to display a message box then quit the win form application I'm writing if a certain type of error occurs when the application starts up. In the main form's...
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...
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...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.