Hi
we are experiencing a few problems with the IDisposable pattern. In this case there is a user control 'ControlA' with a FlowLayoutPanel, which contains more usercontrols 'ControlB'.
When calling Dispose(bool), I check if disposing if true, and if IsDisposed is false. I then try to explicitly dispose each ControlB in the FlowLayoutPanel's Controls collection. However, if does not loop through all controls, only 3 of 8, or 2 of 4.
Dispose(bool disposing)
{
if (disposing)
{
if (!IsDisposed)
{
//unhook events etc.
foreach(ControlB ctrl in flowlayoutpanel.Controls) //<-- there 8 controls
ctrl.Dispose(); //<-- called 3 times only
flp.Controls.Clear();
}
}
//make all members null
}
My quesitons are: 1. Why is this happening? 2. What are best practices and expereinces you guys had with disposing user controls and thei child controls? E.g. do you unsubscribe event handlers at all times, etc.
Thanks!