473,698 Members | 2,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application.Exi t(); 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).ToUpp er() == "MYPAR")) {
isPar = true;
}
}
if (isPar == true) {
myApp myForm = new myApp();
myForm.AppStart Up(true);
} else {
Application.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);
Application.Run (new myApp());
}
}

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

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

Jun 19 '06 #1
4 9507
JIM.H. <JI**@discussio ns.microsoft.co m> wrote:

[snip]
And I am running my application under windows task scheduler although it
passes through Application.Exi t(), 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.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);
Application.Run (new Form());
}
}

static void AppStartUp(bool cmSwitch)
{
Application.Exi t();
}
}
--->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.Exi t() 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.Exi t().

-- 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**@discussio ns.microsoft.co m> wrote:

[snip]
And I am running my application under windows task scheduler although it
passes through Application.Exi t(), 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.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);
Application.Run (new Form());
}
}

static void AppStartUp(bool cmSwitch)
{
Application.Exi t();
}
}
--->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.Exi t() 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.Exi t().

-- Barry

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

Jun 19 '06 #3
JIM.H. <JI**@discussio ns.microsoft.co m> 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.AppStart Up(true);
} else {
Application.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (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.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);
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
8516
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 condition and if it finds it it notifies the user with a MessageBox and then on the next line of code (example in a minute) it calls Application.Exit(). To my astonishment, I stepped through the code with the debugger, and watched it call...
1
17696
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). The form has a really long loop which generates approx. 700 .csv files. I do not create any threads myself (Application.exitthread() doesn't work either). To counteract this I have decided to use the Environment.exit(-1) method instead. What...
6
20078
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 quite a few words in this post but the questions are actually quite similar and should be fairly quick to answer ... (1) What is Happening with the Threads
1
3797
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 Application::Exit()? Does Application::Exit() terminate only the main thread and background threads, and not the foreground threads?
4
10854
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 force the application to exit? See **** below for my comments/questions in a simple example. ****In Sub Main, the Application.Exit works as expected, other sub main code is ignored, and when the end sub is reached the application shuts down....
3
2025
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 I change the End statement to Application.Exit(), the codes after the statement still been executed. So,
3
1555
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 application but when this option is selected the application does not end but continues to the next line of code which tries to setup a filewatcher with the path which does not exist, which then gives an error. please help. Public Sub Check_For_Dir()...
2
2791
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 and shut the application down. My question is, why when you issue Application.Exit() does the program keep executing lines below it before finally closing the app down? If I put a 'return' under Application.Exit() it exits quickly. If I don't...
1
5106
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 fine. But how to do in such following scenario: if I need to give 2 option for user,1. Quit 2. Restart. In Quit option, I use Environment.Exit(0) to confirm the process will be stopped. In Restart option, I can't use Environment.Exit(0) , because...
0
8611
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8904
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.