Click here to Skip to main content
15,886,049 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have created a windows application using c#

I have two buttons one is 'OK' and another one is 'Cancel'.

If click 'OK', it executes one function. (it takes approximately 5 min).
in between, i want to exit from the application.

When i press 'Cancel' button, it won't exit until the function completes.


Please help me, how to close the application when process is running by clicking the 'cancel' button.

Thanks in advance.

Regards,
Posted

If I understood your question correctly, you want to exit the application when it's running a task.

If this is the case, you have to separate the task from the thread running the user interface.

One easy way is to utilize BackgroundWorker[^]. With that, you can run the task separately and still be able to register button press in the UI. When a cancel button is pressed, simply stop the backrground worker and exit the app.
 
Share this answer
 
Comments
CHill60 1-Aug-14 10:04am    
5'd - You're the only one that actually read the question :-)
Wendelius 1-Aug-14 11:34am    
:) Thanks
C#
Application.Exit();


try this
 
Share this answer
 
v2
Comments
sdileep1 1-Aug-14 9:12am    
i tried the same. but it is not happening.

Cancel button is in disable mode.
I can't able to select.
For Exit on Softwate :
Ex 1 :
Application.Exit();
Ex 2 :
Environment.Exit(Environment.ExitCode);

Thx :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900