且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么WPF不使用IDisposable,其后果是什么?

更新时间:2023-11-05 16:59:28

WinForms控件具有句柄,因为它们是Win32控件的包装. WPF控件不是(嗯,窗口不是,但它们托管的控件不是).原因是,毕竟,WPF窗口只是Direct3D渲染上下文,所有控件只是一堆三角形.因此,它们不需要实际注册到操作系统,因此,它们没有句柄(除了窗口和从HwndHost继承的任何东西,当然,这些 Win32对象) ).

WinForms controls have handles because they are wrappers around Win32 controls. WPF controls are not (well, windows are, but the controls they host are not). The reason is that, after all, a WPF window is just a Direct3D rendering context, and all controls are just a bunch of triangles. So, they don't need to be actually registered to the OS, and therefore, they don't have handles (except windows and anything that inherits from HwndHost, of course, which are Win32 objects).

这就是为什么WPF和WinForms之间有如此大的互操作层的原因:WPF控件根本不是Windows对象.

That's why there's such a sizeable interop layer between WPF and WinForms: WPF controls simply aren't Windows objects.