为什么嵌套在选项卡控件中的控件会被销毁两次?
我一直尝试调试为什么关闭 Windows 窗体设计器会使 Visual Studio 崩溃,并通过添加一系列消息框发现,如果我的控件嵌套在 System::Windows::Forms::TabControl 内,则会调用这些控件的析构函数两次。
这是预期的行为吗?有办法避免吗?
I've been trying to debug why closing windows forms designer is crashing visual studio and have discovered by adding a series of message boxes that if my controls are nested inside a System::Windows::Forms::TabControl
the destructor of those controls are called twice.
Is that expected behaviour and is there a way of avoiding it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Dispose() 方法可以被多次调用,没有规则说它不合法。如果您确实覆盖它(在 C++/CLI 中实现析构函数),那么您必须确保您的代码对此具有弹性。通常使用类中的 isDispose 字段来完成。
The Dispose() method may be called more than once, there is no rule that says it isn't legal. If you do override it (implement the destructor in C++/CLI) then you have to make sure that your code is resilient to this. Very commonly done with an isDisposed field in the class.