Here is what I have:
public void FindByID(string id)
{
using (Parser parser = new Parser()) {
if ( parser.LoadUserById(id)) {
ID = parser.FindID();
Name = parser.FindName();
// ...
}
else {
MessageBox.Show("User not found.");
}
} // end using block. parser is disposed so its memory is free to use again.
}
And here is the actual Parser class itself:
public class Parser : IDisposable
{
XDocument doc;
bool userExists = true;
private const string xmlInformationAddress = "http://www.dreamincode.net/forums/xml.php?showuser={0}";
public bool LoadUserById(string userID)
{
try
{
doc = XDocument.Load(String.Format(xmlInformationAddress, userID));
if (doc.Root.Elements().Any())
{
userExists = true;
return true;
}
else
{
userExists = false;
return false;
}
}
catch (Exception e)
{
doc = new XDocument();
userExists = false;
return false;
}
}
}
It says I'm not implementing the Dispose() method, but I'm not sure what is supposed to go inside of that method.