MessageQueueEnumerator 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供一个只进游标,用于枚举消息队列中的消息。
public ref class MessageQueueEnumerator : MarshalByRefObject, IDisposable, System::Collections::IEnumeratorpublic class MessageQueueEnumerator : MarshalByRefObject, IDisposable, System.Collections.IEnumeratortype MessageQueueEnumerator = class
    inherit MarshalByRefObject
    interface IEnumerator
    interface IDisposablePublic Class MessageQueueEnumerator
Inherits MarshalByRefObject
Implements IDisposable, IEnumerator- 继承
- 实现
示例
下面的代码示例循环访问网络中的所有消息队列,并检查每个队列的路径。 最后,它显示网络上的公共队列数。
#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 与网络上的队列进行动态交互。 通过 MessageQueue 类提供的方法可以返回一个MessageQueueEnumerator包含队列动态列表的 ,也可以返回一个数组,该数组包含调用指定方法时队列集合快照。
网络中没有定义的队列顺序。 例如,它们不会按计算机、标签、公共或专用状态或其他用户可访问的条件进行排序。 是 MessageQueueEnumerator 一个游标,初始化为动态列表的头。 可以通过调用 MoveNext将游标移动到枚举的第一个队列。 初始化枚举器后,可以使用 MoveNext 单步执行剩余队列。
不能使用 MessageQueueEnumerator向后单步执行 。 游标仅允许在队列枚举中向前移动。 但是,可以调用 Reset 来重置枚举,并将光标再次放在列表的开头。 由于枚举器是动态的,因此枚举器可以访问超出游标当前位置的队列。 在游标当前位置之前插入的队列如果不首先调用 Reset,则无法访问该队列。
属性
| Current | 获取枚举的当前 MessageQueue。 | 
| LocatorHandle | 获取用于在网络中定位队列的本机消息队列句柄。 | 
方法
| Close() | 释放与枚举数关联的资源。 | 
| CreateObjRef(Type) | 创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。(继承自 MarshalByRefObject) | 
| Dispose() | 释放由 MessageQueueEnumerator 使用的所有资源。 | 
| Dispose(Boolean) | 释放由 MessageQueueEnumerator 占用的非托管资源,还可以另外再释放托管资源。 | 
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| Finalize() | 释放队列控制的资源。 | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetLifetimeService() | 
		已过时.
	 检索控制此实例的生存期策略的当前生存期服务对象。(继承自 MarshalByRefObject) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| InitializeLifetimeService() | 
		已过时.
	 获取生存期服务对象来控制此实例的生存期策略。(继承自 MarshalByRefObject) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| MemberwiseClone(Boolean) | 创建当前 MarshalByRefObject 对象的浅表副本。(继承自 MarshalByRefObject) | 
| MoveNext() | 如果当前有可用的枚举数,使该枚举数前进到枚举的下一个队列。 | 
| Reset() | 重置游标,使其指向枚举的开头。 | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) | 
显式接口实现
| IEnumerator.Current | 获取枚举的当前 MessageQueue。 |