本文整理汇总了C#中SecureString.InsertAt方法的典型用法代码示例。如果您正苦于以下问题:C# SecureString.InsertAt方法的具体用法?C# SecureString.InsertAt怎么用?C# SecureString.InsertAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SecureString
的用法示例。
在下文中一共展示了SecureString.InsertAt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThreadSafe_Stress
public static void ThreadSafe_Stress(int executionTimeSeconds)
{
using (var ss = new SecureString())
{
DateTimeOffset end = DateTimeOffset.UtcNow + TimeSpan.FromSeconds(executionTimeSeconds);
Task.WaitAll(Enumerable.Range(0, Environment.ProcessorCount).Select(_ => Task.Run(() =>
{
var rand = new Random(Task.CurrentId.Value);
while (DateTimeOffset.UtcNow < end)
{
char c = (char)rand.Next(0, char.MaxValue);
switch (rand.Next(12))
{
case 0:
ss.AppendChar(c);
break;
case 1:
ss.InsertAt(0, c);
break;
case 2:
try { ss.SetAt(0, c); } catch (ArgumentOutOfRangeException) { }
break;
case 3:
ss.Copy().Dispose();
break;
case 4:
Assert.InRange(ss.Length, 0, ushort.MaxValue + 1);
break;
case 5:
ss.Clear();
break;
case 6:
try { ss.RemoveAt(0); } catch (ArgumentOutOfRangeException) { }
break;
case 7:
Assert.False(ss.IsReadOnly());
break;
case 8:
Marshal.ZeroFreeCoTaskMemAnsi(SecureStringMarshal.SecureStringToCoTaskMemAnsi(ss));
break;
case 9:
Marshal.ZeroFreeCoTaskMemUnicode(SecureStringMarshal.SecureStringToCoTaskMemUnicode(ss));
break;
case 10:
Marshal.ZeroFreeGlobalAllocAnsi(SecureStringMarshal.SecureStringToGlobalAllocAnsi(ss));
break;
case 11:
Marshal.ZeroFreeGlobalAllocUnicode(SecureStringMarshal.SecureStringToGlobalAllocUnicode(ss));
break;
}
}
})).ToArray());
}
}