本文整理匯總了C#中Microsoft.Win32.RegistryKeyPermissionCheck枚舉的典型用法代碼示例。如果您正苦於以下問題:C# RegistryKeyPermissionCheck枚舉的具體用法?C# RegistryKeyPermissionCheck怎麽用?C# RegistryKeyPermissionCheck使用的例子?那麽, 這裏精選的枚舉代碼示例或許可以為您提供幫助。
在下文中一共展示了RegistryKeyPermissionCheck枚舉的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using Microsoft.Win32;
using System.Diagnostics;
public class Example
{
public static void Main()
{
const int LIMIT = 100;
RegistryKey cu = Registry.CurrentUser;
const string testKey = "RegistryKeyPermissionCheckExample";
Console.WriteLine("Generating {0} key/value pairs.", LIMIT);
RegistryKey rk = cu.CreateSubKey(testKey);
for (int i = 0; i < LIMIT; i++)
{
rk.SetValue("Key" + i, i);
}
rk.Close();
Stopwatch s = new Stopwatch();
// On the default setting, security is checked every time
// a key/value pair is read.
rk = cu.OpenSubKey(testKey, RegistryKeyPermissionCheck.Default);
s.Start();
for (int i = 0; i < LIMIT; i++)
{
rk.GetValue("Key" + i, i);
}
s.Stop();
rk.Close();
long delta1 = s.ElapsedTicks;
s.Reset();
// When the key is opened with ReadSubTree, security is
// not checked when the values are read.
rk = cu.OpenSubKey(testKey, RegistryKeyPermissionCheck.ReadSubTree);
s.Start();
for (int i = 0; i < LIMIT; i++)
{
rk.GetValue("Key" + i, i);
}
s.Stop();
rk.Close();
long delta2 = s.ElapsedTicks;
double faster = (double) (delta1 - delta2) / (double) delta1;
Console.WriteLine("ReadSubTree is {0}% faster for {1} values.",
(faster * 100).ToString("0.0"), LIMIT);
cu.DeleteSubKey(testKey);
}
}
輸出:
Generating 100 key/value pairs. ReadSubTree is 23.4% faster for 100 values.