如何在Windows应用程序中单击按钮时关闭应用程序 [英] How Do I Close The Application When Button Click In Windows Application

查看:105
本文介绍了如何在Windows应用程序中单击按钮时关闭应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我用c创建了一个Windows应用程序



我有两个按钮一个是'OK'而另一个是'取消'。



如果单击确定,它将执行一个功能。 (大概需要5分钟)。

介于两者之间,我想退出应用程序。



当我按下取消按钮,在功能完成之前它不会退出。





请帮助我,如何通过点击运行流程时关闭应用程序'取消'按钮。



提前致谢。



问候,

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,

推荐答案

如果我理解你的问题,你想在运行任务时退出应用程序。



如果这是例如,你必须将任务与运行用户界面的线程分开。



一个简单的方法是利用 BackgroundWorker [ ^ ]。这样,您可以单独运行任务,并且仍然可以在UI中注册按钮按下。当按下取消按钮时,只需停止背景工作者并退出应用程序。
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.


Application.Exit();





试试这个



try this


对于Softwate退出:

Ex 1:

Application.Exit();

例2:

Environment.Exit(Environment.ExitCode);



Thx:)
For Exit on Softwate :
Ex 1 :
Application.Exit();
Ex 2 :
Environment.Exit(Environment.ExitCode);

Thx :)


这篇关于如何在Windows应用程序中单击按钮时关闭应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆