Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Custom Component : Dispose Method

Reply
Thread Tools

Custom Component : Dispose Method

 
 
pete
Guest
Posts: n/a
 
      12-03-2004
Hi Guys,

Apologies for the long post.

I'm following a tutorial on developing components and am having trouble
understanding some of the code. Its a simple RandomNumber component and
although I've removed the comments (to save space) its pretty easy to
follow.

The parts I don't understand are as follows:

1) Visual Studio add a System.ComponentModel.Container variable named
components. Can you tell me what this is for?
2) The tutorial I'm following says I should override the Diposing(bool)
method. Despite providing the code it doesn't explain why I need to do this
or explain exactly what is going on in the code. Can you explain this to me?

Cheers, Pete


using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;

namespace HelperClasses
{
public class RandomNumber : System.ComponentModel.Component
{
private int _minValue;
private int _maxValue;

private System.ComponentModel.Container components = null;

public int MinValue
{
get
{
return _minValue;
}
set
{
_minValue = value;
}
}

public int MaxValue
{
get
{
return _maxValue;
}
set
{
_maxValue = value;
}
}

public RandomNumber(System.ComponentModel.IContainer container)
{
container.Add(this);
InitializeComponent();
}

public RandomNumber()
{
InitializeComponent();

MinValue=0;
MaxValue=100;
}

private void InitializeComponent()
{

}
#endregion


protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);

_minValue = 0;
_maxValue = 0;
}


public int GenerateRandomNumber()
{
Random r = new Random();
return r.Next(MinValue, MaxValue);

}
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding the Dispose method and datasets? Leon ASP .Net 12 02-12-2008 08:34 AM
use of MySQLConnection.dispose and/or MySQLCommand.dispose Antonio Concepcion ASP .Net 3 02-17-2005 06:33 PM
Custom component and the Dispose method pete ASP .Net 0 12-04-2004 01:17 AM
implement dispose method Billy ASP .Net 1 11-13-2003 02:11 AM
Should I close a connection in a dispose method? SS ASP .Net 2 07-03-2003 06:30 PM



Advertisments