472,093 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,093 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 9368
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 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 Mike Johnson | last post: by
2 posts views Thread by John F | 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.