473,411 Members | 1,937 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,411 software developers and data experts.

Application.Exit(); does not end app.

Here is the code I am having problem:
[STAThread()]
static void Main(string[] args)
{
bool isPar = false;
if ((args.Length == 1)) {
if ((args(0).ToUpper() == "MYPAR")) {
isPar = true;
}
}
if (isPar == true) {
myApp myForm = new myApp();
myForm.AppStartUp(true);
} else {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new myApp());
}
}

private void AppStartUp(bool cmSwitch)
{
Application.Exit();
}

And I am running my application under windows task scheduler although it
passes through Application.Exit(), the applications does not end. What might
the problem be?

Jun 19 '06 #1
4 9494
JIM.H. <JI**@discussions.microsoft.com> wrote:

[snip]
And I am running my application under windows task scheduler although it
passes through Application.Exit(), the applications does not end. What might
the problem be?


You haven't provided enough information. A complete, compiling snippet
would be best. For example:

---8<---
using System;
using System.Windows.Forms;

class App
{
[STAThread()]
static void Main(string[] args)
{
bool isPar = false;
if ((args.Length == 1))
{
if ((args[0].ToUpper() == "MYPAR"))
{
isPar = true;
}
}
if (isPar == true)
{
Form myForm = new Form();
AppStartUp(true);
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form());
}
}

static void AppStartUp(bool cmSwitch)
{
Application.Exit();
}
}
--->8---

This application, based on the source code you supplied, exits in both
cases (whether MYPAR was passed or not).

Note that Application.Run() starts a message loop, and doesn't return
until the message loop has terminated. Application.Exit() ultimately
causes this message loop to return, after giving all forms a chance to
close. If you need the application to quit *immediately*, without
notifying any forms of closing etc, you can call Environment.Exit().

-- Barry

--
http://barrkel.blogspot.com/
Jun 19 '06 #2
If parameter is not supplied, AppStartUp is not called and the form is shown.
If there is a parameter. AppStartUp is called and application should exit
since Application.Run(new Form()); is not called. But it does not happen
that way.

"Barry Kelly" wrote:
JIM.H. <JI**@discussions.microsoft.com> wrote:

[snip]
And I am running my application under windows task scheduler although it
passes through Application.Exit(), the applications does not end. What might
the problem be?


You haven't provided enough information. A complete, compiling snippet
would be best. For example:

---8<---
using System;
using System.Windows.Forms;

class App
{
[STAThread()]
static void Main(string[] args)
{
bool isPar = false;
if ((args.Length == 1))
{
if ((args[0].ToUpper() == "MYPAR"))
{
isPar = true;
}
}
if (isPar == true)
{
Form myForm = new Form();
AppStartUp(true);
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form());
}
}

static void AppStartUp(bool cmSwitch)
{
Application.Exit();
}
}
--->8---

This application, based on the source code you supplied, exits in both
cases (whether MYPAR was passed or not).

Note that Application.Run() starts a message loop, and doesn't return
until the message loop has terminated. Application.Exit() ultimately
causes this message loop to return, after giving all forms a chance to
close. If you need the application to quit *immediately*, without
notifying any forms of closing etc, you can call Environment.Exit().

-- Barry

--
http://barrkel.blogspot.com/

Jun 19 '06 #3
JIM.H. <JI**@discussions.microsoft.com> wrote:
If parameter is not supplied, AppStartUp is not called and the form is shown.
If there is a parameter. AppStartUp is called and application should exit
since Application.Run(new Form()); is not called. But it does not happen
that way.


Did you try compiling and running the code I posted? If you supply the
MYPAR parameter, AppStartUp gets called, and the application *does*
exit.

How is your code different from the code I posted? Can you modify the
code I posted to reproduce your problem (and is still complete enough to
compile and run), and repost here?

-- Barry

--
http://barrkel.blogspot.com/
Jun 19 '06 #4
Hi,

Are you using threads?
if (isPar == true) {
myApp myForm = new myApp();
myForm.AppStartUp(true);
} else {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new myApp());
}
}


Not clear what your intentions are here.

Why are you creating a form (and not creating the message pump) in the IF
part?

if you want to end the app just do:

if (isPar != true) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new myApp());
}

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jun 19 '06 #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). ...
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...
3
by: oktave | last post by:
Hi, Anybody would like to tell me ther defference between Application.Exit() and End? I can use End to end my application no matter how many forms and codes after the End statement. But since...
3
by: Mike Johnson | last post by:
I have the following code in form1 and when the application starts this sub is called to check for a path if not found a message box is displayed and then gives the user an option to end the...
2
by: John F | last post by:
Hello All, I have an app that I call a Login form in. I have 2 buttons on the login form. 1 passes back OK and the other Cancel. When I click cancel, I simply want to catch it in the main app...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.