Similar Threads
1. Preventing an application exit from the task bar's right click Close menu
2. Application.exit() vs Environment.exit(-1) vs Application.exitthread()
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 is the difference between the three methods?
Using environment.exit() seems a strange way to do things considering there
is a Application.exit method which claims to do what the Environment.exit()
method does.
3. Application.Exit() not exiting - CSharp/C#
4. Application.Exit() vs Environmrnt.Exit(0)
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 following
application.restart() can't execute never. but if i use Application.Exit(),
the application can restart, but if the user choose quit next time. alas! the
process is going! it won't stop this time.
Hope my desception is clear :)
Pls Help!!!
5. Application::Exit() vs Environment::Exit() in .NET multithreading
6. Preventing an exit
I've created some code (without using the form builder) that is extremely
simple. All it does is, in it's constructor, create a NotifyIcon and make it
visible. It also has a ContextMenu that quits the application.
The problem is, while the icon does display in the system tray when I run
the application, it disappears as soon as I put the mouse over it. On closer
inspection, the program just opens then closes immediately - the icon only
disappears when I make Windows update the tray by moving my mouse onto the
taskbar!
I want my app to stay open until I tell it to close.
I was advised to add a Thread that just yields in its loop, to block the
constructor from exiting, but isn't that a workaround? I want my app to lay
dormant until an event occurs (like the user hitting 'Quit' form the
contextmenu). Surely the framework has some method of achieving that?
Any advice hugely appreciated.
- Dave.
7. Preventing immediate exit of MFC app
8. Application.Run() Application.Exit and the 'Message Pump'
Hi Dave
Thanks for your response - apologies for taking so long to reply, I
decided to take a detour to Threading, as I thought that might help me
with this topic.
With your response and my detour to Threading, I'm more comfortable,
I just have 3 more 'itty bitty' questions that I hope will clear
the confusion I have over Application.Exit() ....
As before, set up a project with one form, and that form just has a
close button. In the close button's 'on click' event handler,
just type:
this.close();
Add a class to the project and put in the start routine:
public class StartUp
{
static void Main()
{
//This should 'block' until the user clicks the close button
in the form
Application.Run(new ExForm());
//Should this second call to Application.Run work ? It does!
Application.Run(new ExForm());
Debug.WriteLine("Finished Main");
}
}
At this point the application should consist of a form - ExForm, and
a StartUp class.
(1)
In the above example, you should find that a form shows, and code
execution is "blocked" until you click close. After clicking
close, a second form shows, and code execution 'blocks' until you
click close. Then finally, the application terminates. Confirmation
Question - The closing of the first form does not 'mortally
wound' the message pump and it can get started again for the second
call to Application.Run?
(2)
Keep everything the same, but in the form, change the close button's
'on click' event handler to:
Application.Exit();
In this example, you should find that the first form shows, and code
execution is "blocked" until you click close. After clicking
close, a second form "flashes" on and off the screen. Confirmation
Question - The closing of the first form causes
'Application.Exit()' which seems to 'mortally wound' the
message pump. When the second call to Application.Run occurs, the
message pump cannot be revived, and therefore code execution cannot be
blocked. Execution falls through to the debug.WriteLine and then the
end of static void Main is reached, causing the application to
terminate.
(3)
With the close button's 'on click' event handler still calling
'Application.Exit', put this code into the StartUp class:
public class StartUp
{
static void Main()
{
ExForm myExForm = new ExForm();
myExForm.Show();
Application.Run(); //This call to Application.Run should block
//Should this second call to Application.Run work ? It does!
Application.Run(new ExForm());
Debug.WriteLine("Finished Main");
}
}
In this above example, you should find that a form shows, and code
execution is "blocked" until you click close. After clicking
close, a second form shows, and code execution 'blocks' until you
click close. Then finally, the application terminates.
Unlike scenario (2), in this scenario the message pump is not
'mortally wounded ???? Is this something to do with the fact that we
show the form then call Application.Run() with no parameters ???? Que
!?!
Cheers
Bill