Disposing local resources

M

mehdi_mousavi

Hi folks,
Consider a dialog that is being generated within the visual
environment:

//HERE'S THE DESIGNER-GENERATED CODE...
partial class CustomerDlg
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
}

Now, consider the file that's being created to be modified by the
developer:

public partial class CustomerDlg : Common.CommonBaseDlg
{
private DataSet myLocalResourceThatNeedsToBeDisposed;
}

The question is that how am I supposed to override the Dispose method,
while the designer-generated code has been doing so before? In other
words, how am I supposed to dispose
myLocalResourceThatNeedsToBeDisposed? Is it safe to move the Dispose
method from the designer-generated code to the main code?

FYI: I'm using VS2005, .NET Framework 2.0.

Any help would be highly appreciated,

Cheers,
Mehdi
 
G

Guest

I may be missing something, but it seems like you could do the following:

public partial class CustomerDlg : Common.CommonBaseDlg
{
private DataSet myLocalResourceThatNeedsToBeDisposed;
protected override void Dispose(bool disposing)
{
if (disposing)
{
myLocalResourceThatNeedsToBeDisposed.Dispose();
}
base.Dispose(disposing);
}
}
 
M

mehdi_mousavi

Well, If I do so, I'll receive the following error:

Type 'CustomerDlg' already defines a member called 'Dispose' with the
same parameter types.

Any idea?
 

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