C# Queue Synchronized

Description

Queue Synchronized returns a Queue wrapper that is synchronized (thread safe).

Syntax

Queue.Synchronized has the following syntax.


[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true)]
public static Queue Synchronized(
  Queue queue
)

Parameters

Queue.Synchronized has the following parameters.

  • queue - The Queue to synchronize.

Returns

Queue.Synchronized method returns A Queue wrapper that is synchronized (thread safe).

Example

The following example shows how to synchronize a Queue, determine if a Queue is synchronized and use a synchronized Queue.


using System;/*from  www . j a  v  a 2s. c  o m*/
using System.Collections;
public class SamplesQueue  {

   public static void Main()  {
      Queue myQ = new Queue();
      myQ.Enqueue( "A" );

      Queue mySyncdQ = Queue.Synchronized( myQ );

      Console.WriteLine(myQ.IsSynchronized);
      Console.WriteLine(mySyncdQ.IsSynchronized);
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack