Я видел несколько соглашений о присвоении имен для потоков в.NET.
Некоторые предпочитают использовать 't' в начале имени (напр. Поток tMain ), но я не думаю, что он имеет любое действительное значение. Вместо этого, почему не только используют простые описательные имена (переменные строки) такой как HouseKeeping, Планировщик и так далее.
Both the Panel and the Form class have a Controls collection property, which has a Clear() method...
MyPanel.Controls.Clear();
or
MyForm.Controls.Clear();
But Clear()
doesn't call dispose()
(All it does is remove he control from the collection), so what you need to do is
List<Control> ctrls = new List<Control>(MyPanel.Controls);
MyPanel.Controls.Clear();
foreach(Control c in ctrls )
c.Dispose();
You need to create a separate list of the references because Dispose also will remove the control from the collection, changing the index and messing up the foreach...
I don't believe there is a way to do this all at once. You can just iterate through the child controls and call each of their dispose methods one at a time:
foreach(var control in this.Controls)
{
control.Dispose();
}
You don't give much detail as to why.
This happens in the Dispose override method of the form (in form.designer.cs). It looks like this:
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
You didn't share if this were ASP.Net or Winforms. If the latter, you can do well enough by first calling SuspendLayout()
on the panel. Then, when finished, call ResumeLayout()
.