" //清理托管资源“ F&安培; * CK [英] " //Clean Up managed resources " f&*ck

查看:53
本文介绍了" //清理托管资源“ F&安培; * CK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起我不完美的英语


i真的f& * ckin生气


这种关于处置的常见模式:

///////////////////////////////////////////// /////////////


公共类MyClass:IDisposable

{

private bool IsDisposed = false;

public void Dispose()

{

Dispose(true);

GC.SupressFinalize(这个);

}

protected void Dispose(bool Diposing)

{

if(!IsDisposed)

{

if(Disposing)

{

//清理托管资源

}

//清理非托管资源

}

IsDisposed = true;

}

~MyClass()

{

Dispose(false);

}


}

////////////////////////////


大多数事情都很清楚 -

有两种方式可以调用处理 - 一种来自终结者(只有

unmana) ged managed会自动释放

如果我明白的话)第二个是Dispose()(由管理和非管理的
手)但是


到底是什么? //清理托管资源意思是


pozdrawiam(问候)

C Kinbote

解决方案

< blockquote> Koliber,


这意味着如果Dispose

方法的disposing参数为true,那么你想在任何引用上调用Dispose你有

实现IDisposable。假设你的班级有一个SqlConnection,它是b $ b持有的。如果处理参数为真,那么你会打电话给

处理连接,否则你不会。

-

- 尼古拉斯Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Koliber(js)" < pr ************** @ poczta.onet.plwrote in message

news:11 ************** ********@l77g2000hsb.googlegr oups.com ...


对不起我不完美的英语


i am f& * ckin生气


这种关于处置的常见模式:


////////// //////////////////////////////////////////////// <无线电通信/>

公共类MyClass:IDisposable

{

private bool IsDisposed = false;

public void Dispose( )

{

Dispose(true);

GC.SupressFinalize(this);

}


protected void Dispose(bool Diposing)

{

if(!IsDisposed)

{

if(Disposing)

{

//清理托管资源

}

/ /清理非托管资源

}

IsDisposed = true;

}


~MyClass( )

{

Dispose(false);

}


}

////////////////////////////


大部分事情都很清楚 -

有两种方式可以调用dispose - 一种来自终结者(只有

unmanaged managed会免费)自动

,如果我明白的话)第二次通过Dispose()(由管理和非管理的

手)但是b $

到底是怎么回事" //清理托管资源意思是


pozdrawiam(问候)

C Kinbote



在18 Maj,21:03,Nicholas Paldino [.NET / C#MVP]"

< m ... @ spam.guard.caspershouse.comwrote:


Koliber,


这意味着如果Dispose

方法的处理参数为true,那么你想在你有的任何参考上调用Dispose

实现IDisposable。假设你的班级有一个SqlConnection,它是b $ b持有的。如果处理参数为真,那么你会打电话给

处理连接,否则,你不会。



否否否否

Net告诉我,SqlConnection是非托管资源(资源我需要管理的资源) - 你说

它是托管资源吗?如果是这样,什么是非管理资源?


K.


Koliber,


SqlConnection是一个托管资源。非托管

资源的一个示例是通过调用非托管代码或

a文件句柄,或套接字句柄或任何类型的指针或句柄获得的窗口句柄那个你不会被CLR管理的


-

- Nicholas Paldino [.NET / C#MVP] < br $> b $ b - mv*@spam.guard.caspershouse.com


" Koliber(js)" < pr ************** @ poczta.onet.plwrote in message

news:11 ************** ******@l77g2000hsb.googlegrou ps.com ...


On 18 Maj,21:03,Nicholas Paldino [.NET / C#MVP ]

< m ... @ spam.guard.caspershouse.comwrote:


> Koliber,

这意味着如果Dispose
方法的处理参数为true,那么你想在任何实现IDisposable的引用上调用Dispose。假设你的类有一个它坚持的SqlConnection。如果处理参数为真,那么你会打电话
处理连接,否则,你不会。



否否否

Net告诉我,SqlConnection是非托管资源(资源我需要管理的资源) - 你说

它是托管资源吗?如果是这样,什么是非管理资源?


K.



sorry for my not perfect english

i am really f&*ckin angry

in this common pattern about dispose:
//////////////////////////////////////////////////////////

Public class MyClass:IDisposable
{
private bool IsDisposed=false;
public void Dispose()
{
Dispose(true);
GC.SupressFinalize(this);
}
protected void Dispose(bool Diposing)
{
if(!IsDisposed)
{
if(Disposing)
{
//Clean Up managed resources
}
//Clean up unmanaged resources
}
IsDisposed=true;
}
~MyClass()
{
Dispose(false);
}

}
////////////////////////////

most of things are clear -
there are two ways of calling dispose - one from finalizer (only
unmanaged managed will free automatically
if i do understand) second by Dispose() (managed and unamanaged by
hand) BUT

what the hell " //Clean Up managed resources " mean

pozdrawiam (greetings)
C Kinbote

解决方案

Koliber,

What this means is that if you the disposing parameter of the Dispose
method is true, then you want to call Dispose on any reference that you have
which implements IDisposable. Say your class had a SqlConnection that it
was holding onto. If the disposing parameter was true, then you would call
Dispose on the connection, otherwise, you would not.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Koliber (js)" <pr**************@poczta.onet.plwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...

sorry for my not perfect english

i am really f&*ckin angry

in this common pattern about dispose:
//////////////////////////////////////////////////////////

Public class MyClass:IDisposable
{
private bool IsDisposed=false;
public void Dispose()
{
Dispose(true);
GC.SupressFinalize(this);
}
protected void Dispose(bool Diposing)
{
if(!IsDisposed)
{
if(Disposing)
{
//Clean Up managed resources
}
//Clean up unmanaged resources
}
IsDisposed=true;
}
~MyClass()
{
Dispose(false);
}

}
////////////////////////////

most of things are clear -
there are two ways of calling dispose - one from finalizer (only
unmanaged managed will free automatically
if i do understand) second by Dispose() (managed and unamanaged by
hand) BUT

what the hell " //Clean Up managed resources " mean

pozdrawiam (greetings)
C Kinbote



On 18 Maj, 21:03, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:

Koliber,

What this means is that if you the disposing parameter of the Dispose
method is true, then you want to call Dispose on any reference that you have
which implements IDisposable. Say your class had a SqlConnection that it
was holding onto. If the disposing parameter was true, then you would call
Dispose on the connection, otherwise, you would not.

No no no no
Net says to me that SqlConnection is unmanaged resource (resource I
should manage) - you say that
it is managed resource? If so what is unamanaged resource?

K.


Koliber,

SqlConnection is a managed resource. An example of an unmanaged
resource is a window handle that you obtained by calling unmanaged code, or
a file handle, or a socket handle, or any kind of pointer or handle that you
are holding onto which is not managed by the CLR.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Koliber (js)" <pr**************@poczta.onet.plwrote in message
news:11********************@l77g2000hsb.googlegrou ps.com...

On 18 Maj, 21:03, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:

>Koliber,

What this means is that if you the disposing parameter of the Dispose
method is true, then you want to call Dispose on any reference that you
have
which implements IDisposable. Say your class had a SqlConnection that it
was holding onto. If the disposing parameter was true, then you would
call
Dispose on the connection, otherwise, you would not.

No no no no
Net says to me that SqlConnection is unmanaged resource (resource I
should manage) - you say that
it is managed resource? If so what is unamanaged resource?

K.



这篇关于&QUOT; //清理托管资源“ F&安培; * CK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆