Can someone help me to speed up the loading of application.
I'm creating a program like a Registry Editor but for viewing purposes only.
The program loads too slow because of my Try-catch for the security issues.
Public Class Form1
Private Function CreateNodes(ByVal vParentNode As TreeNode, ByVal vRegKey As RegistryKey) As TreeNode
For Each vSubKeyName As String In vRegKey.GetSubKeyNames()
Dim vSubKey As RegistryKey = vRegKey.OpenSubKey(vSubKeyName, RegistryKeyPermissionCheck.Default, Security.AccessControl.RegistryRights.ReadKey)
Dim vChildNode As New TreeNode(vSubKeyName)
vChildNode = CreateNodes(vChildNode, vSubKey)
Catch ex As SecurityException
Catch ex As Exception
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim vRegKeyLocalMachine As RegistryKey = Registry.LocalMachine
Dim vRegKeyClassesRoot As RegistryKey = Registry.ClassesRoot
Dim vParentNode As New TreeNode(vRegKeyLocalMachine.Name)
Dim vParentNode2 As New TreeNode(vRegKeyClassesRoot.Name)
vParentNode = CreateNodes(vParentNode, vRegKeyLocalMachine)
vParentNode2 = CreateNodes(vParentNode2, vRegKeyClassesRoot)
Dim root As TreeNode
root = New TreeNode(My.Computer.Name)
or do you have code bank there to use or borrow?
Edited 24-Jan-13 6:25am
You could try moving the try..catch code outside of the for..next loop in your CreateNodes code
The first solution is correct, you should move the try..catch outside the loop to correct the performance problems.
However, you can also use the RegistryRights enumeration in the RegistrySecurity class that is part of System.Security.AccessControl to test to see if your application is running under an account with sufficient permissions to do what you are wanting to do. There is also a GetAccessControl method on the RegistyKey class that allows you to get the user rights associated with a specific key.
Checking the permissions first and failing gracefully is a much better approach that assuming everything will work then trying to catch the possibilities in a catch block.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)