本文整理汇总了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.