我应该处理什么 [英] What should I Dispose

查看:70
本文介绍了我应该处理什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该处理什么。


例如,在下面我应该处理什么以及如果我不会发生什么?b $ b不是吗?


谢谢


Dim PS作为新的PrinterSettings


PS.PrinterName = pD.DefaultPageSettings.PrinterSettings。 PrinterName


PS.DefaultPageSettings.Landscape = False


如果PS.IsValid那么


昏暗GrPrinter As Graphics = PS.CreateMeasurementGraphics()


Dim Hdc As IntPtr = GrPrinter.GetHdc()


--snip ---

解决方案

" ** **开发" < RE ************* @ a-znet.com> schrieb

我应该处理什么。


所有的东西

- 你创造了

- 并且有一个Dispose方法

- 而你不再需要

- 而且没有其他人需要了

例如,在下面我应该处理什么以及如果我不干什么会发生什么? t?

谢谢

Dim PS作为新的PrinterSettings

PS.PrinterName = pD.DefaultPageSettings.PrinterSettings.PrinterName
PS.DefaultPageSettings.Landscape = False

如果PS.IsValid然后

Dim GrPrinter As Graphics = PS.CreateMeasurementGraphics()

Dim Hdc As IntPtr = GrPrinter.GetHdc()



GrPrinter.releasehdc(hdc)

grPrinter.dispose


hdc没有什么可以实现Disposable模式,但它指向一个必须释放的非托管资源



Armin


开发人员,


所有拥有非托管资源的东西有一个处理方法。


请注意,20%的方法已经处理掉,因为它们从组件模型继承了




处理每个标签,文本框,按钮等没有多大意义只需

,因为它有方法处理。

请注意设计师表单和组件的一部分是

标准Idisposable实现的代码。


非托管资源(不要将其与托管*代码混淆) *)主要是与处理器外部或操作系统的一部分进行交互的方法相关的
,而不是真正的Net类。 (Showdialog使用操作系统中的对话框。)


然而,它有更多的时间,它没有意义。


例如,在system.data命名空间(adonet)中,AFAIK永远不会使用dispose的原因。该命名空间完全继承了组件

模型。


我希望这会有所帮助,


Cor

" ** **开发" < RE ************* @ a-znet.com> schreef in bericht

新闻:eI ************** @ TK2MSFTNGP11.phx.gbl ...

我应该处理什么。

例如,在下面我应该处理什么,如果我不会发生什么?

谢谢

昏暗PS作为新的PrinterSettings

PS.PrinterName = pD.DefaultPageSettings.PrinterSettings.PrinterName

PS.DefaultPageSettings.Landscape = False

如果PS.IsValid然后

Dim GrPrinter As Graphics = PS.CreateMeasurementGraphics()

Dim Hdc As IntPtr = GrPrinter.GetHdc()

--snip-- -



PS怎么样 - 需要配置?

如果没有,为什么不呢。


非常感谢

例如,在下面我应该处理什么以及如果我将会发生什么
不是吗?

谢谢

昏暗的PS作为新的打印机配置

PS.PrinterNam e = pD.DefaultPageSettings.PrinterSettings.PrinterName

PS.DefaultPageSettings.Landscape = False

如果PS.IsValid那么

Dim GrPrinter As Graphics = PS.CreateMeasurementGraphics()

Dim Hdc As IntPtr = GrPrinter.GetHdc()



GrPrinter.releasehdc(hdc)
grPrinter.dispose

hdc无法实现Disposable模式,但它指向一个必须释放的非托管资源。

Armin



What should I Dispose.

For example, in the following what should I Dispose and what happens if I
don''t?

Thanks

Dim PS As New PrinterSettings

PS.PrinterName = pD.DefaultPageSettings.PrinterSettings.PrinterName

PS.DefaultPageSettings.Landscape = False

If PS.IsValid Then

Dim GrPrinter As Graphics = PS.CreateMeasurementGraphics()

Dim Hdc As IntPtr = GrPrinter.GetHdc()

--snip---

解决方案

" **Developer**" <RE*************@a-znet.com> schrieb

What should I Dispose.
Everything that
- you create
- and has a Dispose method
- and you don''t need anymore
- and nobody else needs anymore
For example, in the following what should I Dispose and what happens if I
don''t?

Thanks

Dim PS As New PrinterSettings

PS.PrinterName = pD.DefaultPageSettings.PrinterSettings.PrinterName

PS.DefaultPageSettings.Landscape = False

If PS.IsValid Then

Dim GrPrinter As Graphics = PS.CreateMeasurementGraphics()

Dim Hdc As IntPtr = GrPrinter.GetHdc()


GrPrinter.releasehdc(hdc)
grPrinter.dispose

The hdc is nothing that can implement the Disposable pattern, but it points
to an unmanaged resource that has to be released.
Armin


Developer,

Everything that has unmanaged resources and has a dispose method.

Be aware that 20% of the methods have dispose, just because they inherit
from component model.

It has not much sense to dispose every label, textbox, button etc just
because it has the method dispose.
Be aware that in the designer part of a form and a component is the code for
the standard Idisposable implementation.

Unmanaged resources (don''t mix this up with managed *code*) are mostly
related to methods which interact outside your processor or a part of the OS
and not really a Net class. (Showdialog uses the dialog from the OS).

However there are much more times that it is useless than that it has sense.

By instance in the system.data namespace (adonet) there is AFAIK never a
reason to use dispose. That namespace inherits completly the component
model.

I hope this helps,

Cor
" **Developer**" <RE*************@a-znet.com> schreef in bericht
news:eI**************@TK2MSFTNGP11.phx.gbl...

What should I Dispose.

For example, in the following what should I Dispose and what happens if I
don''t?

Thanks

Dim PS As New PrinterSettings

PS.PrinterName = pD.DefaultPageSettings.PrinterSettings.PrinterName

PS.DefaultPageSettings.Landscape = False

If PS.IsValid Then

Dim GrPrinter As Graphics = PS.CreateMeasurementGraphics()

Dim Hdc As IntPtr = GrPrinter.GetHdc()

--snip---



What about PS - needs a Dispose?
If not, why not.

Thanks a lot

For example, in the following what should I Dispose and what happens if I
don''t?

Thanks

Dim PS As New PrinterSettings

PS.PrinterName = pD.DefaultPageSettings.PrinterSettings.PrinterName

PS.DefaultPageSettings.Landscape = False

If PS.IsValid Then

Dim GrPrinter As Graphics = PS.CreateMeasurementGraphics()

Dim Hdc As IntPtr = GrPrinter.GetHdc()


GrPrinter.releasehdc(hdc)
grPrinter.dispose

The hdc is nothing that can implement the Disposable pattern, but it
points to an unmanaged resource that has to be released.
Armin



这篇关于我应该处理什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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