473,396 Members | 2,089 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,396 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 2456
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.