PC Review


Reply
Thread Tools Rate Thread

Application.Exit(); does not end app.

 
 
=?Utf-8?B?SklNLkgu?=
Guest
Posts: n/a
 
      19th Jun 2006
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(false);
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?

 
Reply With Quote
 
 
 
 
Barry Kelly
Guest
Posts: n/a
 
      19th Jun 2006
JIM.H. <(E-Mail Removed)> 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(false);
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/
 
Reply With Quote
 
=?Utf-8?B?SklNLkgu?=
Guest
Posts: n/a
 
      19th Jun 2006
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. <(E-Mail Removed)> 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(false);
> 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/
>

 
Reply With Quote
 
Barry Kelly
Guest
Posts: n/a
 
      19th Jun 2006
JIM.H. <(E-Mail Removed)> 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/
 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      19th Jun 2006
Hi,

Are you using threads?

> if (isPar == true) {
> myApp myForm = new myApp();
> myForm.AppStartUp(true);
> } else {
> Application.EnableVisualStyles();
> Application.SetCompatibleTextRenderingDefault(false);
> 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(false);
Application.Run(new myApp());
}



--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.Exit() vs Environmrnt.Exit(0) =?Utf-8?B?VGFvZ2U=?= Microsoft C# .NET 1 19th Apr 2007 03:37 AM
application.exit, application.exitthread exit application problem =?Utf-8?B?TWlrZSBTaWx2ZXI=?= Microsoft Dot NET Framework Forms 2 24th Nov 2004 03:14 AM
Application.exit() vs Environment.exit(-1) vs Application.exitthread() Brendan Miller Microsoft C# .NET 1 5th Feb 2004 08:13 AM
RE: How can I safe exit my application when the user terminates the application from the Control panel? Dolphin White Microsoft Dot NET Compact Framework 3 6th Sep 2003 01:12 AM
RE: RE: How can I safe exit my application when the user terminates the application from the Control panel? Dolphin White Microsoft Dot NET Compact Framework 0 4th Sep 2003 04:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:29 PM.