English 中文(简体)
是否处置一个与处置子女和自己等同的小组?
原标题:Is disposing a panel equivalent to disposing its children plus itself?

在以下级别:

class MyPanel : Panel
{
    ...
    protected override void Dispose(bool disposing)
    {
        // My code here
    }
}

以下两种代码样本是否相等?

base.Dispose(disposing);

v

if (disposing)
{
    List<Control> ctrls = new List<Control>(this.Controls);
    this.Controls.Clear();  
    foreach(Control c in ctrls)
    {
         c.Dispose();
    }
}
base.Dispose(disposing);

如果它们产生不同的影响,会是什么?

<><>Edit>: 我要求这样做是因为,无论出于何种原因,在处置任何儿童之前,首先冻结我的方案( disating是真实的,而Controls则包含2项控制,而第二种方式则是罚款。 如果我能乐意使用第二种方法,那那是巨大的。

问题回答

两者并不相同,因为你可以很容易地看到《<条码>的实施情况。 处置,使用反射器(在它仍然自由时可以做)

例如,如果你只向小组提出反对意见,它将在要求处置子女之前,把每个儿童控制权的处置权从父母中删除。

不过,我同意科迪·格雷的话——你需要说明为什么要冻结而不是试图“在地毯下解决问题”你拟议的工作。

通常,你没有明确地向小组提出反对意见——如果你这样做的话,你需要确保你能够正确管理控制寿命和控制权的所有权。

The thing to do is to start simplifying your app step by step until it no longer freezes - to work out what is causing the freeze (for example, by removing the Timers you mentioned one by one - that sounds suspect). Once you have a very simple example that exhibits the problem it will be easier for you (or someone here) to work out what s going on.





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.