Disposing local resources

  • Thread starter Thread starter mehdi_mousavi
  • Start date Start date
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
 
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);
}
}
 
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?
 
Back
Top