風輕雲淡
专注DotNET开发
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
posts - 1, comments - 0, trackbacks - 0
公告
2009年1月21日
释放模式
Code
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication1
{
class
MyResources : IDisposable
{
private
bool
disposed
=
false
;
public
void
Dispose()
{
Dispose(
true
);
}
public
void
Close()
{
Dispose(
true
);
}
~
MyResources()
{
Dispose(
false
);
}
private
void
Dispose(
bool
disposing)
{
if
(
!
this
.disposed)
{
if
(disposing)
{
Console.WriteLine(
"
调用所引用对象的Dispose()方法
"
);
}
Console.WriteLine(
"
释放类本身所使用的的非托管资源
"
);
this
.disposed
=
true
;
if
(disposing)
{
GC.SuppressFinalize(
this
);
}
}
}
}
class
Program
{
static
void
Main(
string
[] args)
{
MyResources Mr
=
new
MyResources();
try
{
Console.WriteLine(
"
Mr做的事情
"
);
}
finally
{
Mr.Dispose();
}
}
}
}
释放模式。。。。。。。。。。。。。
posted @ 2009-01-21 02:54 Legendary 阅读(26) 评论(0)
编辑