当前位置:网站首页>C#中关闭窗体的四种方法
C#中关闭窗体的四种方法
2022-07-28 02:22: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:代表程序非正常退出。
边栏推荐
猜你喜欢

Using pytorch's tensorboard visual deep learning indicators | pytorch series (25)

@Valid的作用(级联校验)以及常用约束注解的解释说明

Docker高级篇-Docker容器内Redis集群配置

Unexpected harvest of epic distributed resources, from basic to advanced are full of dry goods, big guys are strong!

Data center construction (III): introduction to data center architecture

Scheme sharing | experts gather to jointly explore accent AI speech recognition

Full of dry goods, hurry in!!! Easy to master functions in C language

Which of the four solutions of distributed session do you think is the best?

Pychart shortcut key for quickly modifying all the same names on the whole page

数据中台建设(三):数据中台架构介绍
随机推荐
基于JSP&Servlet实现的众筹平台系统
上位机与MES对接的几种方式
优炫数据库客户端如何认证
数据中台建设(三):数据中台架构介绍
Es6.--promise, task queue and event cycle
[stream] basic knowledge of stream
Pytest the best testing framework
Selenium+pytest+allure comprehensive exercise
每日刷题巩固知识
My approval & signature function of conference OA project
Opengauss source code, what ide tools are used to manage, edit and debug?
Interview experience: first tier cities move bricks and face software testing posts. 5000 is enough
JS event object 2 e.charcode character code e.keycode key code box moves up, down, left and right
How to authenticate Youxuan database client
决策树与随机森林学习笔记(1)
trivy【1】工具扫描运用
clientY vs pageY
[stream] parallel stream and sequential stream
Comprehensive case
@The function of valid (cascade verification) and the explanation of common constraint annotations