Form.Dispose does not invoke InputPanel.Dispose

  • Thread starter Thread starter tomj
  • Start date Start date
T

tomj

I use CompactFramework 2.0.

The code generated by Designer does not invoke
InputPanel.Dispose when form is disposing. And
I cannot understand how it can work without
manual fixing.

Example:

using (Form2 form = new Form2())
{
form.ShowDialog();
}
// Form2 instance is disposed, but inputPanel1 is not

Now if I show or hide SIP in other forms, Form2.inputPanel1
will also get event EnabledChanged and it will lead to an error(
because the form it belongs is already disposed)

private void inputPanel1_EnabledChanged(object sender, EventArgs e)
{
//this code throw exception because form instance is disposed
this.Text = "Form2 " + inputPanel1.Enabled.ToString();
}

So, to fix the problem I need manually fix Designer code

protected override void Dispose(bool disposing)
{
// Bug fix
if (disposing)
{
inputPanel1.Dispose();
}

if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

Is it a bug?

Thanks,
Tom.
 
You're certain Form2 is getting disposed? A Form shown with ShowDialog does
not get disposed when closed - that's by design.

-Chris
 
Form2 instance is disposed.

USING statement help (C# Reference):
Defines a scope, outside of which an object or objects will be
disposed.

Thanks,
Tom.
 
Only if you are explicity calling Dispose(true) from within your
implementation of IDisposable's Dispose.
 
Back
Top