當前位置: 首頁>>代碼示例>>C#>>正文


C# RegistryKeyPermissionCheck枚舉代碼示例

本文整理匯總了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);
    }
}
開發者ID:.NET開發者,項目名稱:Microsoft.Win32,代碼行數:59,代碼來源:RegistryKeyPermissionCheck

輸出:

Generating 100 key/value pairs.
ReadSubTree is 23.4% faster for 100 values.


注:本文中的Microsoft.Win32.RegistryKeyPermissionCheck枚舉示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。