C# Queue SyncRoot

Description

Queue SyncRoot gets an object that can be used to synchronize access to the Queue.

Syntax

Queue.SyncRoot has the following syntax.


public virtual Object SyncRoot { get; }

Example

The following code example shows how to lock the collection using the SyncRoot during the entire enumeration. Retrieving the value of this property is an O(1) operation.


using System.Collections;
using System;/*from  w w w.j  ava2 s.  c  o m*/
public class MainClass
{
    public static void Main(String[] argv)
    {
        Queue myCollection = new Queue();
        lock (myCollection.SyncRoot)
        {
            foreach (object item in myCollection)
            {
                // Insert your code here.
            }
        }

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack