WindowInteropHelper.Handle — do I need to release it?

情到浓时终转凉″ 提交于 2019-12-20 07:28:48

问题


In WPF I'm getting IntPtr handle using this code:

IntPtr mainWindowHandle = new WindowInteropHelper(Application.Current.MainWindow).Handle

When I finish using this handle, do I need to release it in anyway (e.g. using Marshal.FreeHGlobal() method) ?

EDIT: I was thinking about Marshal.FreeHGlobal(), not Marshal.Release(), sorry!


回答1:


This is not in any way related to COM, Marshal.Release() does not apply. You simply get a copy of the native window handle, it does not have to be released. You need to stop using the handle when the window is destroyed. Signaled by the Window.Close event.



来源:https://stackoverflow.com/questions/15312883/windowinterophelper-handle-do-i-need-to-release-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!