Array.SyncRoot Property
来源:互联网 发布:配音软件包租婆 编辑:程序博客网 时间:2024/06/11 10:45
Syntax:
SyncRoot
This property returns a synchronization object for the current array. Arrays are not inherently thread-safe. Synchronize access to the array with the synchronization object.
virtual object SyncRoot{ get;}
Example:
Accesses to arrays are easily synchronized with the lock statement, where the SyncRoot object is the parameter.
using System;
using System.Collections.Generic;
using System.Threading;
public class MyClass
{
public static void Main()
{
Array.Sort(zArray);
Thread t1=new Thread(
new ThreadStart(DisplayForward));
Thread t2=new Thread(
new ThreadStart(DisplayReverse));
t1.Start();
t2.Start();
RL();
}
private static int [] zArray={1,5,4,2,4,2,9,10};
public static void DisplayForward() {
lock(zArray.SyncRoot) {
Console.Write(" Forward: ");
foreach(int number in zArray) {
Console.Write(number+" ");
}
}
}
public static void DisplayReverse() {
lock(zArray.SyncRoot) {
Array.Reverse(zArray);
Console.Write(" Reverse: ");
foreach(int number in zArray) {
Console.Write(number+" ");
}
Array.Reverse(zArray);
}
}
#region Helper methods
private static void WL(object text, params object[] args)
{
Console.WriteLine(text.ToString(), args);
}
private static void RL()
{
Console.ReadLine();
}
private static void Break()
{
System.Diagnostics.Debugger.Break();
}
#endregion
}
using System.Collections.Generic;
using System.Threading;
public class MyClass
{
public static void Main()
{
Array.Sort(zArray);
Thread t1=new Thread(
new ThreadStart(DisplayForward));
Thread t2=new Thread(
new ThreadStart(DisplayReverse));
t1.Start();
t2.Start();
RL();
}
private static int [] zArray={1,5,4,2,4,2,9,10};
public static void DisplayForward() {
lock(zArray.SyncRoot) {
Console.Write(" Forward: ");
foreach(int number in zArray) {
Console.Write(number+" ");
}
}
}
public static void DisplayReverse() {
lock(zArray.SyncRoot) {
Array.Reverse(zArray);
Console.Write(" Reverse: ");
foreach(int number in zArray) {
Console.Write(number+" ");
}
Array.Reverse(zArray);
}
}
#region Helper methods
private static void WL(object text, params object[] args)
{
Console.WriteLine(text.ToString(), args);
}
private static void RL()
{
Console.ReadLine();
}
private static void Break()
{
System.Diagnostics.Debugger.Break();
}
#endregion
}
o(∩_∩)o...
- Array.SyncRoot Property
- 多线程同步 - Array.SyncRoot 属性
- SyncRoot 属性
- Synchronized vs SyncRoot
- SyncRoot 属性应用
- ibatis select in property with array
- C# Hashtable Synchronized vs SyncRoot
- C# Hashtable Synchronized vs SyncRoot
- C# Hashtable Synchronized vs SyncRoot
- C# Hashtable Synchronized vs SyncRoot
- Synchronized静态方法和SyncRoot
- 关于返回 Array 的 Property的性能测试
- @property (copy) NSMutableArray *array; 这个写法会出什么问题
- @property (copy) NSMutableArray *array; 这个写法会出什么问题
- iOS @property (copy) NSMutableArray *array;用copy、strong出现问题
- property
- property
- Property
- 将ListView中的内容导出到Word和Excel
- hide process
- 状态机的两种写法
- 浙江大学教授令人深省的演讲!
- 将DBGrid中的内容导出到Excel文档
- Array.SyncRoot Property
- PowerShell 2.0 CTP版新特性效果图
- ASP.Net: 为 CheckBoxList 和 RadioButtonList 中的各 ListItem 项目编写客户端脚本
- 用53款全免费软件重装Windows(xbeta译)
- 我在CSDN的Blog安家了,呵呵,
- c/c++笔试面试题(1)
- c/c++笔试面试题(2)
- 买足彩英超直播免费看
- c/c++笔试面试题(3)