当前位置:网站首页>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:代表程序非正常退出。
边栏推荐
- LeetCode-138-复制带随机指针的链表
- Cannot find current proxy: Set ‘exposeProxy‘ property on Advised to ‘true‘ to make it available
- (ICLR-2022)TADA! Time adaptive convolution for video understanding
- MySQL - multi table query and case explanation
- Synchronized理论
- Is it safe to apply for public REITs account by mobile phone?
- VTK (the Visualization Toolkit) loads STL models
- 多线程学习笔记-1.CAS
- 实用工具网站推荐
- JS刷题计划——数组
猜你喜欢

【Swoole系列3.1】进程、线程、协程,面试你被问了吗?

The role of @requestmapping in the project and how to use it

Simulated 100 questions and simulated examination of refrigeration and air conditioning equipment operation examination in 2022

分布式事务-seata

Seata 入门简介

JS刷题计划——数组

MySQL - function and constraint commands

基础模块及算例#pytorch学习

Verification palindrome string II of leetcode simple question

Brian behrendorf, general manager of openssf Foundation: it is estimated that there will be 420million open sources in 2026
随机推荐
2022茶艺师(中级)考试题模拟考试题库及答案
J3:Redis主从复制
How to solve the problem that win11 has been switched on after upgrading
Briefly describe the 11 core functional modules of MES system
LeetCode简单题之数组能形成多少数对
NLP 学习之路
What aspects should be considered in the selection of MES system?
【C语言实现】----动态/文件/静态通讯录
微软默默给 curl 捐赠一万美元,半年后才通知
LeetCode-138-复制带随机指针的链表
Unity farm 2 - planting system
Use notes of Lichuang EDA
EN 1504-6混凝土结构保护和修理用产品钢筋锚固—CE认证
基础模块及算例#pytorch学习
Last blog post
JS question brushing plan - array
5款WPS Office最佳海外替代品
2022 welder (elementary) operation certificate examination question bank and simulation examination
密码一致,总显示如下图
JS question brushing plan - linked list