WithEvents/Handles 比 Remove/AddHandler 更好? [英] WithEvents/Handles better than Remove/AddHandler?

查看:27
本文介绍了WithEvents/Handles 比 Remove/AddHandler 更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从内存的角度来看(在使用后移除添加的处理程序等),WithEventsHandles 的使用是否优于 RemoveHandlerAddHandler?

From a memory point of view (remove an added handler after utilization, etc.), is WithEvents and Handles usage preferable to RemoveHandler and AddHandler?

一个相关的 Stack Overflow 问题是事件处理程序和内存泄漏.

A related Stack Overflow question is Event handler and memory leaks.

推荐答案

这取决于您要实现的目标.如果您有多个事件处理程序必须在表单/对象的生命周期内处理各种控件的事件,那么 WithEvents 和 Handles 是最简单的方法.在设置活动方面,该语言将为您完成所有繁琐的工作.另一方面,如果您倾向于在表单的生命周期内断开与事件的连接,那么 AddHandler 和 RemoveHandler 是更好的选择.

It depends on what you're trying to achieve. If you have several event handlers which must handle events for various controls during the lifetime of a form/object then WithEvents and Handles is the easiest way to go. The language will do all of the dirty work for you in terms of setting up the event. On the other hand, if you tend to disconnect from events during the lifetime of the form, AddHandler and RemoveHandler are better options.

这篇关于WithEvents/Handles 比 Remove/AddHandler 更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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