> Money says he's using Nodes.Add() instead of Nodes.AddRange(). That would
> be key in this kind of situation.
Hi Shawn,
I agree with Jason that AddRange is preferable, but your problem clearly is
different. In your foreach loop you do a call to RegistryKey.OpenSubKey but
don't store the result in any variable:
> foreach (string key in names)
> {
> regKey.OpenSubKey(path + @"\" + key);
Now that means that the next block will always operate on the same registry
key:
> if (regKey.SubKeyCount > 0)
> {
> TreeNode childNode = new TreeNode("*");
> child.Nodes.Add(childNode);
> }
If this registry key is HKEY_CLASSES_ROOT, then regKey.SubKeyCount will take
an enormous amount of time to complete and you're calling it over and over.
Try the following and I'm quite sure that your tree is populated in a few
seconds. After you've verified that, you should go for AddRange to improve
it furhter.
if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();
tvwRegistryKeys.BeginUpdate();
foreach (string key in names)
{
RegistryKey regSubkey = regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);
if (regSubkey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}
node.Nodes.Add(child);
regSubkey.Close();
}
regKey.Close();
}
Michael
>> Money says he's using Nodes.Add() instead of Nodes.AddRange(). That
>> would be key in this kind of situation.
[quoted text clipped - 30 lines]
> Thanks,
> Shawn
Jason Newell - 23 Dec 2005 19:09 GMT
Michael,
If you're interested, I threw together a little C# 2005 regedit program
to show you what I'm talking about. I compared it to the Windows
regedit and it's slightly slower but nothing like what you described. I
don't know that you can get much faster with .NET. Let me know if you
have any questions.
You can download the source from my website.
www.jasonnewell.net/public/Examples/Regedit.zip
Jason Newell
> Hi Shawn,
>
[quoted text clipped - 81 lines]
>>Thanks,
>>Shawn
Jason Newell - 23 Dec 2005 19:18 GMT
Sorry, I meant Shawn in my last post.
Jason Newell
> Michael,
>
[quoted text clipped - 96 lines]
>>> Thanks,
>>> Shawn
Shawn B. - 24 Dec 2005 01:50 GMT
Works like a champ. Now I'll just have to figure out what I'm doing wrong.
Thanks,
Shawn
http://www.zenofdotnet.com
> Michael,
>
[quoted text clipped - 96 lines]
>>>Thanks,
>>>Shawn
Shawn B. - 24 Dec 2005 01:42 GMT
Everytime I run it I keept getting "Object reference not set to an instance
of an object when it tries to return an instance by OpenSubKey(...); The
key path looks valid, I'm not sure what to do.
Thanks,
Shawn
> Hi Shawn,
>
[quoted text clipped - 82 lines]
>> Thanks,
>> Shawn