惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - dannyr|一个都不能少!

DipperRiver.Net通信协议设计 计划开发memcache 的.net版本,命名DipperRiver.Net Net1.1添加目录共享,并设置访问权限 Access数据库的文本、备注数据类型的COLUMN_FLAGS说明 生命诚可贵 function object(functor) ... Dev GridControl的Outlook风格定制 WinForm MDI动态加载form DevExpress's tip 检测浏览器类型的js Spry1.4 下载 Spry PreRelease 1.4 发布 Spry Framework入门(五)——数据集过滤及淡入淡出效果 Flex2.0文件上传功能(Flex2.0正式版) 关于JSON Spry Framework入门(四)——XML数据集排序 Spry Framework入门(三)——框架结构 Spry Framework入门(二)——XML数据集及主从表显示 Spry Framework入门(一)——XML数据集及显示
如何关闭子线程?征集析构函数与多线程的讨论!
dannyr|一个都不能少! · 2007-09-28 · via 博客园 - dannyr|一个都不能少!

如何关闭子线程?征集析构函数与多线程的讨论!

下面的代码是可以执行,大家都来说说为什么这个程序不会自动退出?
也就是说mian函数执行完毕后,为什么.net不会释放ThreadEx对象?

using System;
using System.Threading;

public class ThreadEx : IDisposable{    
    
private Thread thread;
    
private volatile bool bExit;
    
public ThreadEx(){
        Console.WriteLine(
"ThreadEx output");
        bExit 
= false;
        thread 
= new Thread(OnThread);
        thread.Start();
    }


    
~ThreadEx(){
        Console.WriteLine(
"~ThreadEx output");
        bExit 
= true;
    }


    
private void OnThread(){
        
while(true){
            
if(bExit){
                
break;
            }

            Console.WriteLine(
"Thread output");
            Thread.Sleep(
1000);
        }

        Console.WriteLine(
"Thread exit");
    }


    
private void Close(){
        bExit 
= true;
    }


    
public void Dispose() {
        
// TODO:  添加 ThreadEx.Dispose 实现
        Console.WriteLine("~Dispose output");
        bExit 
= true;
    }


    
static void Main(){
        ThreadEx threadEx 
= new ThreadEx();
    }

}

posted @ 2007-09-28 16:42  dannyr|一个都不能少!  阅读(4475)  评论(16)    收藏  举报

刷新页面返回顶部