Form.Dispose does not invoke InputPanel.Dispose

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.
 
G

Guest

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

-Chris
 
T

tomj

Form2 instance is disposed.

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

Thanks,
Tom.
 
S

Simon Hart

Only if you are explicity calling Dispose(true) from within your
implementation of IDisposable's Dispose.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top