当前位置:网站首页>C#中关闭窗体的四种方法
C#中关闭窗体的四种方法
2022-07-26 18:10:00 【黄昏和星空】
close():
指仅关闭当前窗体,如果不是主窗体(包含主线程的窗体,并非MDI窗体)的话,是无法退出整个程序的。如果有托管线程也无法退出。
此方法会调用 dispose() 方法,所以它会自动的帮我们释放内存,除了以下两种情况:(1)该窗体是多文档应用程序(MDI)的一部分并且此窗体不可见;(2)此窗体是“模态”窗体。
close() 方法执行的时候会触发两个事件:Form_Closing 和 Form_Closeed 事件,Form_Closing 是在窗体关闭时执行,Form_Closed 是在窗体关闭之后执行,所以如果想取消关闭窗体,可以在 Form_Closing 事件里取消。Application.Exit():
强制所有消息中止,退出所有的窗体,但是若有托管线程(非主线程),也无法干净地退出。Application.ExitThread():
强制中止调用线程上的所有消息,同样面临其它线程无法正确退出的问题。System.Environment.Exit(0);
这是最彻底的退出方式,不管什么线程都被强制退出,把程序结束的很干净。 参数0:代表程序正常退出;参数1:代表程序非正常退出。
边栏推荐
- Unity 农场 2 —— 种植系统
- 时空预测4-graph wavenet
- 支持代理直连Oracle数据库,JumpServer堡垒机v2.24.0发布
- (ICLR-2022)TADA!用于视频理解的时间自适应卷积
- Reentrantlock learning --- basic method
- The United States, Japan and South Korea jointly developed 6G with the intention of anti surpassing, but China has long been prepared
- ReentrantLock学习之---基础方法
- MySQL日志介绍
- PMP practice once a day | don't get lost in the exam -7.26 (including agility + multiple choices)
- 第九章 实用建模技术
猜你喜欢
随机推荐
密码一致,总显示如下图
2022年焊工(初级)操作证考试题库及模拟考试
Tensor RT's int8 quantization principle
Support proxy direct connection to Oracle database, jumpserver fortress v2.24.0 release
MongoDB stats统计集合占用空间大小
The first letter of leetcode simple question appears twice
Tensorflow GPU 1.15 installation
模型定义#pytorch学习
Redis learning notes-2. Use of the client
JVM内存模型之Volatile关键字
5款WPS Office最佳海外替代品
Sentinel isolation and degradation
2022 Shanghai safety officer C certificate operation certificate examination question bank simulated examination platform operation
自动化测试的使用场景
JS刷题计划——数组
议程速递 | 7月27日分论坛议程一览
立创EDA使用笔记
2022 chemical automation control instrument test question simulation test platform operation
ZbxTable 2.0 重磅发布!6大主要优化功能!
VTK (the Visualization Toolkit) loads STL models









