MessageQueueEnumerator 类

定义

提供一个只进游标,用于枚举消息队列中的消息。Provides a forward-only cursor to enumerate through messages in a message queue.

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
继承
MessageQueueEnumerator
实现

示例

下面的代码示例将循环访问网络中的所有消息队列,并检查每个队列的路径。The following code example iterates through all the message queues in the network, and examines the path for each queue. 最后,它显示网络上公用队列的数量。Finally, it displays the number of public queues on the network.

#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

注解

用于 MessageQueueEnumerator 与网络上的队列进行动态交互。Use MessageQueueEnumerator for dynamic interaction with queues on the network. 通过 MessageQueue 类提供的方法可以返回一个 MessageQueueEnumerator 包含动态队列列表的,也可以返回一个数组,该数组包含调用指定方法时队列集合的快照。Methods available through the MessageQueue class can return either a MessageQueueEnumerator containing a dynamic list of queues, or an array that contains a snapshot of the queue collection at the time the specified method was called.

网络中未定义队列的顺序。There is no defined ordering of queues in a network. 它们不是按顺序进行排序,例如,按计算机、标签、公共或私有状态或其他用户可访问的条件。They are not ordered, for example, by computer, label, public or private status, or other user-accessible criteria. MessageQueueEnumerator是游标,初始化为动态列表的开头。A MessageQueueEnumerator is a cursor, initialized to the head of a dynamic list. 可以通过调用将光标移到枚举的第一个队列 MoveNextYou can move the cursor to the first queue of the enumeration by calling MoveNext. 枚举器初始化完成后,可以使用前进到 MoveNext 剩余队列。After the enumerator has been initialized, you can use MoveNext to step forward through the remaining queues.

不可能向后移动 MessageQueueEnumeratorIt is not possible to step backward with a MessageQueueEnumerator. 游标只允许在队列枚举中向前移动。A cursor only allows forward movement through the queue enumeration. 但是,可以调用 Reset 来重置枚举,并将光标再次置于列表的开头。However, you can call Reset to reset the enumeration and put the cursor at the beginning of the list again. 由于枚举器是动态的,因此,枚举数追加到游标当前位置之外的队列可以由枚举器访问。Because the enumerator is dynamic, a queue that is appended beyond the cursor's current position can be accessed by the enumerator. 如果不首先调用 Reset,则无法访问在游标当前位置之前插入的队列。A queue that is inserted before the cursor's current position cannot be accessed without first calling Reset.

属性

Current

获取枚举的当前 MessageQueueGets the current MessageQueue of the enumeration.

LocatorHandle

获取用于在网络中定位队列的本机消息队列句柄。Gets the native Message Queuing handle used to locate queues in a network.

方法

Close()

释放与枚举数关联的资源。Frees the resources associated with the enumerator.

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

释放由 MessageQueueEnumerator 使用的所有资源。Releases all resources used by the MessageQueueEnumerator.

Dispose(Boolean)

释放由 MessageQueueEnumerator 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the MessageQueueEnumerator and optionally releases the managed resources.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
Finalize()

释放队列控制的资源。Releases the resources held by the queue.

GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()
已过时。

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()
已过时。

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
MoveNext()

如果当前有可用的枚举数,使该枚举数前进到枚举的下一个队列。Advances the enumerator to the next queue of the enumeration, if one is currently available.

Reset()

重置游标,使其指向枚举的开头。Resets the cursor, so it points to the beginning of the enumeration.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

IEnumerator.Current

获取枚举的当前 MessageQueueGets the current MessageQueue of the enumeration.

适用于

另请参阅