MessageQueueEnumerator Classe

Definizione

Fornisce un cursore forward-only per enumerare i messaggi in una coda di messaggi.

public ref class MessageQueueEnumerator : MarshalByRefObject, IDisposable, System::Collections::IEnumerator
public class MessageQueueEnumerator : MarshalByRefObject, IDisposable, System.Collections.IEnumerator
type MessageQueueEnumerator = class
    inherit MarshalByRefObject
    interface IEnumerator
    interface IDisposable
Public Class MessageQueueEnumerator
Inherits MarshalByRefObject
Implements IDisposable, IEnumerator
Ereditarietà
MessageQueueEnumerator
Implementazioni

Esempio

Nell'esempio di codice seguente viene eseguita l'iterazione di tutte le code di messaggi nella rete ed esamina il percorso di ogni coda. Infine, visualizza il numero di code pubbliche nella rete.

#using <System.dll>
#using <System.Messaging.dll>

using namespace System;
using namespace System::Messaging;

//**************************************************
// Iterates through message queues and examines the
// path for each queue. Also displays the number of
// public queues on the network.
//**************************************************
void ListPublicQueues()
{
   
   // Holds the count of private queues.
   int numberQueues = 0;
   
   // Get a cursor into the queues on the network.
   MessageQueueEnumerator^ myQueueEnumerator = MessageQueue::GetMessageQueueEnumerator();
   
   // Move to the next queue and read its path.
   while ( myQueueEnumerator->MoveNext() )
   {
      
      // Increase the count if priority is Lowest.
      Console::WriteLine( myQueueEnumerator->Current->Path );
      numberQueues++;
   }

   
   // Display final count.
   Console::WriteLine( "Number of public queues: {0}", numberQueues );
   return;
}


//**************************************************
// Provides an entry point into the application.
//   
// This example uses a cursor to step through the
// message queues and list the public queues on the
// network.
//**************************************************
int main()
{
   
   // Output the count of Lowest priority messages.
   ListPublicQueues();
}
using System;
using System.Messaging;

namespace MyProject
{
    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //		
        // This example uses a cursor to step through the
        // message queues and list the public queues on the
        // network.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Output the count of Lowest priority messages.
            myNewQueue.ListPublicQueues();
                        
            return;
        }

        //**************************************************
        // Iterates through message queues and examines the
        // path for each queue. Also displays the number of
        // public queues on the network.
        //**************************************************
        
        public void ListPublicQueues()
        {
            // Holds the count of private queues.
            uint numberQueues = 0;
    
            // Get a cursor into the queues on the network.
            MessageQueueEnumerator myQueueEnumerator =
                MessageQueue.GetMessageQueueEnumerator();

            // Move to the next queue and read its path.
            while(myQueueEnumerator.MoveNext())
            {
                // Increase the count if priority is Lowest.
                Console.WriteLine(myQueueEnumerator.Current.Path);
                numberQueues++;
            }

            // Display final count.
            Console.WriteLine("Number of public queues: " +
                numberQueues.ToString());
            
            return;
        }
    }
}
Imports System.Messaging



Public Class MyNewQueue


        
        ' Provides an entry point into the application.
        '		 
        ' This example uses a cursor to step through the
        ' message queues and list the public queues on the
        ' network.
        

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue()

            ' Output the count of Lowest priority messages.
            myNewQueue.ListPublicQueues()

            Return

        End Sub


        
        ' Iterates through message queues and examines the
        ' path for each queue. Also displays the number of
        ' public queues on the network.
        

        Public Sub ListPublicQueues()

            ' Holds the count of private queues.
            Dim numberQueues As Int32 = 0

            ' Get a cursor into the queues on the network.
            Dim myQueueEnumerator As MessageQueueEnumerator = _
                MessageQueue.GetMessageQueueEnumerator()

            ' Move to the next queue and read its path.
            While myQueueEnumerator.MoveNext()
                ' Increase the count if the priority is Lowest.
                Console.WriteLine(myQueueEnumerator.Current.Path)
                numberQueues += 1
            End While

            ' Display final count.
            Console.WriteLine(("Number of public queues: " + _
                numberQueues.ToString()))

            Return

        End Sub

End Class

Commenti

Usare MessageQueueEnumerator per l'interazione dinamica con le code in rete. I metodi disponibili tramite la MessageQueue classe possono restituire un MessageQueueEnumerator oggetto contenente un elenco dinamico di code o una matrice che contiene uno snapshot della raccolta di code al momento della chiamata del metodo specificato.

Non esiste un ordinamento definito di code in una rete. Non vengono ordinati, ad esempio, per computer, etichetta, stato pubblico o privato o per altri criteri accessibili dall'utente. Un MessageQueueEnumerator oggetto è un cursore, inizializzato all'inizio di un elenco dinamico. È possibile spostare il cursore nella prima coda dell'enumerazione chiamando MoveNext. Dopo l'inizializzazione dell'enumeratore, è possibile usare MoveNext per eseguire le code rimanenti.

Non è possibile procedere all'indietro con un oggetto MessageQueueEnumerator. Un cursore consente solo lo spostamento in avanti tramite l'enumerazione della coda. Tuttavia, è possibile chiamare Reset per reimpostare l'enumerazione e posizionare di nuovo il cursore all'inizio dell'elenco. Poiché l'enumeratore è dinamico, è possibile accedere a una coda che viene aggiunta oltre la posizione corrente del cursore dall'enumeratore. Non è possibile accedere a una coda che viene inserita prima della posizione corrente del cursore senza prima chiamare Reset.

Proprietà

Nome Descrizione
Current

Ottiene l'oggetto corrente MessageQueue dell'enumerazione .

LocatorHandle

Ottiene l'handle di accodamento messaggi nativo utilizzato per individuare le code in una rete.

Metodi

Nome Descrizione
Close()

Libera le risorse associate all'enumeratore.

CreateObjRef(Type)

Crea un oggetto che contiene tutte le informazioni pertinenti necessarie per generare un proxy utilizzato per comunicare con un oggetto remoto.

(Ereditato da MarshalByRefObject)
Dispose()

Rilascia tutte le risorse usate da MessageQueueEnumerator.

Dispose(Boolean)

Rilascia le risorse non gestite usate da MessageQueueEnumerator e, facoltativamente, rilascia le risorse gestite.

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
Finalize()

Rilascia le risorse contenute nella coda.

GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetLifetimeService()
Obsoleti.

Recupera l'oggetto servizio di durata corrente che controlla i criteri di durata per questa istanza.

(Ereditato da MarshalByRefObject)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
InitializeLifetimeService()
Obsoleti.

Ottiene un oggetto servizio di durata per controllare i criteri di durata per questa istanza.

(Ereditato da MarshalByRefObject)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
MemberwiseClone(Boolean)

Crea una copia superficiale dell'oggetto corrente MarshalByRefObject .

(Ereditato da MarshalByRefObject)
MoveNext()

Sposta l'enumeratore alla coda successiva dell'enumerazione, se disponibile.

Reset()

Reimposta il cursore, quindi punta all'inizio dell'enumerazione.

ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

Nome Descrizione
IEnumerator.Current

Ottiene l'oggetto corrente MessageQueue dell'enumerazione .

Si applica a

Vedi anche