Array.SyncRoot : Array « System « C# / C Sharp by API






Array.SyncRoot

  

using System;
using System.Threading;

public class Starter {
    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();
    }

    private static int[] zArray = { 1, 5, 4, 2, 4, 2, 9, 10 };
    public static void DisplayForward() {
        lock (zArray.SyncRoot) {
            Console.Write("\nForward: ");
            foreach (int number in zArray) {
                Console.Write(number);
            }
        }
    }

    public static void DisplayReverse() {
        lock (zArray.SyncRoot) {
            Array.Reverse(zArray);
            Console.Write("\nReverse: ");
            foreach (int number in zArray) {
                Console.Write(number);
            }
            Array.Reverse(zArray);
        }
    }
}

   
    
  








Related examples in the same category

1.Array.AsReadOnly
2.Array.BinarySearch
3.Array.Clone
4.Array.ConvertAll
5.Array.Copy
6.Array.CopyTo
7.Array.Count
8.Array.CreateInstance
9.Array.Exists
10.Array.Find
11.Array.FindAll
12.Array.ForEach
13.Array.GetEnumerator()
14.Array.GetLength()
15.Array.GetLowerbound
16.Array.GetUpperBound
17.Array.IndexOf
18.Array.LastIndexOf
19.Array.Length
20.Array.Rank
21.Array.Resize
22.Array.Reverse
23.Array.Reverse(nums, 1, 3)
24.Array.Sort
25.Array.Sort(names, Comparer.DefaultInvariant)