MessageQueue.Peek MessageQueue.Peek MessageQueue.Peek MessageQueue.Peek Method

定義

傳回佇列中第一個訊息的複本,但不從佇列中移除訊息。Returns a copy of the first message in the queue without removing the message from the queue.

多載

Peek() Peek() Peek() Peek()

傳回而不移除 (窺視) 這個 MessageQueue 所參考佇列中的第一個訊息。Returns without removing (peeks) the first message in the queue referenced by this MessageQueue. Peek() 方法是同步的,因此會封鎖目前的執行緒,直到訊息可以使用為止。The Peek() method is synchronous, so it blocks the current thread until a message becomes available.

Peek(TimeSpan) Peek(TimeSpan) Peek(TimeSpan) Peek(TimeSpan)

傳回而不移除 (窺視) 這個 MessageQueue 所參考佇列中的第一個訊息。Returns without removing (peeks) the first message in the queue referenced by this MessageQueue. Peek() 方法是同步的,因此會封鎖目前的執行緒,直到訊息可以使用或發生指定的逾時為止。The Peek() method is synchronous, so it blocks the current thread until a message becomes available or the specified time-out occurs.

Peek(TimeSpan, Cursor, PeekAction) Peek(TimeSpan, Cursor, PeekAction) Peek(TimeSpan, Cursor, PeekAction)

使用指定的游標傳回而不移除 (窺視) 佇列中的目前或下一則訊息。Returns without removing (peeks) the current or next message in the queue, using the specified cursor. Peek() 方法是同步的,因此會封鎖目前的執行緒,直到訊息可以使用或發生指定的逾時為止。The Peek() method is synchronous, so it blocks the current thread until a message becomes available or the specified time-out occurs.

Peek() Peek() Peek() Peek()

傳回而不移除 (窺視) 這個 MessageQueue 所參考佇列中的第一個訊息。Returns without removing (peeks) the first message in the queue referenced by this MessageQueue. Peek() 方法是同步的,因此會封鎖目前的執行緒,直到訊息可以使用為止。The Peek() method is synchronous, so it blocks the current thread until a message becomes available.

public:
 System::Messaging::Message ^ Peek();
public System.Messaging.Message Peek ();
member this.Peek : unit -> System.Messaging.Message
Public Function Peek () As Message

傳回

表示佇列中第一個訊息的 MessageThe Message that represents the first message in the queue.

例外狀況

存取訊息佇列方法時發生錯誤。An error occurred when accessing a Message Queuing method.

範例

下列範例會在佇列Peek上使用方法。The following examples use the Peek method on a queue.

在第一個範例中, 應用程式會等到訊息在佇列中可供使用為止。In the first example, the application waits until a message becomes available in the queue. 請注意, 第一個範例不會存取抵達的訊息;它只會暫停處理, 直到訊息抵達為止。Note that the first example does not access the message that arrives; it merely pauses processing until a message arrives. 如果訊息已經存在於佇列中, 則會立即傳回。If a message already exists in the queue, it will return immediately.

在第二個範例中, 包含應用程式定義Order類別的訊息會傳送至佇列, 然後從佇列中查看。In the second example, a message that contains an application-defined Order class is sent to the queue, and then peeked from the queue.

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;

// This class represents an object the following example 
// sends to a queue and receives from a queue.
ref class Order
{
public:
   int orderId;
   DateTime orderTime;
};


/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
public:

   //*************************************************
   // Posts a notification when a message arrives in 
   // the queue S"monitoredQueue". Does not retrieve any 
   // message information when peeking the message.
   //*************************************************
   void NotifyArrived()
   {
      // Connect to a queue.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\monitoredQueue" );

      // Specify to retrieve no message information.
      myQueue->MessageReadPropertyFilter->ClearAll();

      // Wait for a message to arrive. 
      Message^ emptyMessage = myQueue->Peek();

      // Post a notification when a message arrives.
      Console::WriteLine( "A message has arrived in the queue." );
      return;
   }


   //*************************************************
   // Sends an Order to a queue.
   //*************************************************
   void SendMessage()
   {
      // Create a new order and set values.
      Order^ sentOrder = gcnew Order;
      sentOrder->orderId = 3;
      sentOrder->orderTime = DateTime::Now;

      // Connect to a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );

      // Send the Order to the queue.
      myQueue->Send( sentOrder );
      return;
   }

   //*************************************************
   // Peeks a message containing an Order.
   //*************************************************
   void PeekFirstMessage()
   {
      // Connect to a queue.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );

      // Set the formatter to indicate the body contains an Order.
      array<Type^>^p = gcnew array<Type^>(1);
      p[ 0 ] = Order::typeid;
      myQueue->Formatter = gcnew XmlMessageFormatter( p );
      try
      {
         // Peek and format the message. 
         Message^ myMessage = myQueue->Peek();
         Order^ myOrder = static_cast<Order^>(myMessage->Body);

         // Display message information.
         Console::WriteLine( "Order ID: {0}", myOrder->orderId );
         Console::WriteLine( "Sent: {0}", myOrder->orderTime );
      }
      catch ( MessageQueueException^ ) 
      {
         // Handle Message Queuing exceptions.
      }
      // Handle invalid serialization format.
      catch ( InvalidOperationException^ e ) 
      {
         Console::WriteLine( e->Message );
      }

      // Catch other exceptions as necessary.
      return;
   }
};

//*************************************************
// Provides an entry point into the application.
//         
// This example posts a notification that a message
// has arrived in a queue. It sends a message 
// containing an other to a separate queue, and then
// peeks the first message in the queue.
//*************************************************
int main()
{
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;

   // Wait for a message to arrive in the queue.
   myNewQueue->NotifyArrived();

   // Send a message to a queue.
   myNewQueue->SendMessage();

   // Peek the first message in the queue.
   myNewQueue->PeekFirstMessage();
   return 0;
}
using System;
using System.Messaging;

namespace MyProject
{

	// This class represents an object the following example 
	// sends to a queue and receives from a queue.
	public class Order
	{
		public int orderId;
		public DateTime orderTime;
	};	

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

		//**************************************************
		// Provides an entry point into the application.
		//		 
		// This example posts a notification that a message
		// has arrived in a queue. It sends a message 
		// containing an other to a separate queue, and then
		// peeks the first message in the queue.
		//**************************************************

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

			// Wait for a message to arrive in the queue.
			myNewQueue.NotifyArrived();

			// Send a message to a queue.
			myNewQueue.SendMessage();	

			// Peek the first message in the queue.
			myNewQueue.PeekFirstMessage();
						
			return;
		}


		//**************************************************
		// Posts a notification when a message arrives in 
		// the queue "monitoredQueue". Does not retrieve any 
		// message information when peeking the message.
		//**************************************************
		
		public void NotifyArrived()
		{

			// Connect to a queue.
			MessageQueue myQueue = new 
				MessageQueue(".\\monitoredQueue");
	
			// Specify to retrieve no message information.
			myQueue.MessageReadPropertyFilter.ClearAll();

			// Wait for a message to arrive. 
			Message emptyMessage = myQueue.Peek();

			// Post a notification when a message arrives.
			Console.WriteLine("A message has arrived in the queue.");

			return;

		}


		//**************************************************
		// Sends an Order to a queue.
		//**************************************************
		
		public void SendMessage()
		{
			
			// Create a new order and set values.
			Order sentOrder = new Order();
			sentOrder.orderId = 3;
			sentOrder.orderTime = DateTime.Now;

			// Connect to a queue on the local computer.
			MessageQueue myQueue = new MessageQueue(".\\myQueue");

			// Send the Order to the queue.
			myQueue.Send(sentOrder);

			return;
		}


		//**************************************************
		// Peeks a message containing an Order.
		//**************************************************
		
		public void PeekFirstMessage()
		{
			// Connect to a queue.
			MessageQueue myQueue = new MessageQueue(".\\myQueue");
	
			// Set the formatter to indicate the body contains an Order.
			myQueue.Formatter = new XmlMessageFormatter(new Type[]
				{typeof(MyProject.Order)});
			
			try
			{
				// Peek and format the message. 
				Message myMessage =	myQueue.Peek(); 
				Order myOrder = (Order)myMessage.Body;

				// Display message information.
				Console.WriteLine("Order ID: " + 
					myOrder.orderId.ToString());
				Console.WriteLine("Sent: " + 
					myOrder.orderTime.ToString());
			}
			
			catch (MessageQueueException)
			{
				// Handle Message Queuing exceptions.
			}

			// Handle invalid serialization format.
			catch (InvalidOperationException e)
			{
				Console.WriteLine(e.Message);
			}
			
			// Catch other exceptions as necessary.

			return;

		}
	}
}
Imports System.Messaging



    ' This class represents an object the following example 
    ' sends to a queue and peeks from a queue.
    Public Class Order
        Public orderId As Integer
        Public orderTime As DateTime
    End Class 'Order


   
    Public Class MyNewQueue


        
        ' Provides an entry point into the application.
        '		 
        ' This example posts a notification that a message
        ' has arrived in a queue. It sends a message 
        ' containing an other to a separate queue, and then
        ' peeks the first message in the queue.
        

        Public Shared Sub Main()

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

            ' Wait for a message to arrive in the queue.
            myNewQueue.NotifyArrived()

            ' Send a message to a queue.
            myNewQueue.SendMessage()

            ' Peek the first message in the queue.
            myNewQueue.PeekFirstMessage()

            Return

        End Sub


        
        ' Posts a notification when a message arrives in 
        ' the queue "monitoredQueue". Does not retrieve any 
        ' message information when peeking the message.
        
        Public Sub NotifyArrived()

            ' Connect to a queue.
            Dim myQueue As New MessageQueue(".\monitoredQueue")

            ' Specify to retrieve no message information.
            myQueue.MessageReadPropertyFilter.ClearAll()

            ' Wait for a message to arrive. 
            Dim emptyMessage As Message = myQueue.Peek()

            ' Post a notification when a message arrives.
            Console.WriteLine("A message has arrived in the queue.")

            Return

        End Sub


        
        ' Sends an Order to a queue.
        

        Public Sub SendMessage()

            ' Create a new order and set values.
            Dim sentOrder As New Order()
            sentOrder.orderId = 3
            sentOrder.orderTime = DateTime.Now

            ' Connect to a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Send the Order to the queue.
            myQueue.Send(sentOrder)

            Return

        End Sub


        
        ' Peeks a message containing an Order.
        

        Public Sub PeekFirstMessage()

            ' Connect to a queue.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Set the formatter to indicate body contains an Order.
            myQueue.Formatter = New XmlMessageFormatter(New Type() _
                {GetType(Order)})

            Try

                ' Peek and format the message. 
                Dim myMessage As Message = myQueue.Peek()
                Dim myOrder As Order = CType(myMessage.Body, Order)

                ' Display message information.
                Console.WriteLine(("Order ID: " + _
                    myOrder.orderId.ToString()))
                Console.WriteLine(("Sent: " + _
                    myOrder.orderTime.ToString()))

            Catch m as MessageQueueException
                ' Handle Message Queuing exceptions.


            Catch e As InvalidOperationException
                ' Handle invalid serialization format.
                Console.WriteLine(e.Message)

                ' Catch other exceptions as necessary.

            End Try

            Return

        End Sub

End Class 'MyNewQueue

備註

使用這個多載來查看佇列, 或等待訊息存在於佇列中。Use this overload to peek a queue, or to wait until a message exists in the queue.

Peek方法會讀取 (但不會移除) 佇列中的第一個訊息。The Peek method reads, but does not remove, the first message from the queue. 因此, 除非較高Peek優先順序的訊息抵達佇列, 否則重複呼叫會傳回相同的訊息。Therefore, repeated calls to Peek return the same message, unless a higher priority message arrives in the queue. 另一方面Receive , 方法會讀取和移除佇列中的第一個訊息。The Receive method, on the other hand, both reads and removes the first message from the queue. 因此, 重複Receive呼叫, 因此會傳回不同的訊息。Repeated calls to Receive, therefore, return different messages.

訊息佇列會根據優先順序和抵達時間來排序佇列中的訊息。Message Queuing orders messages in the queue according to priority and arrival time. 只有在較高的優先順序時, 才會將較新的訊息放在舊版中。A newer message is placed before an older one only if it is of a higher priority.

當目前的執行緒可接受進行封鎖並同時等候訊息到達佇列時,請使用 PeekUse Peek when it is acceptable for the current thread to be blocked while it waits for a message to arrive in the queue. 因為此多載不會指定超時時間, 所以應用程式可能會無限期地等候。Because this overload does not specify a time-out, the application might wait indefinitely. 當您需要應用程式繼續執行而不要等候,請使用非同步的 BeginPeek 方法。If you need the application processing to continue without waiting, use the asynchronous BeginPeek method. 或者, 您可以使用Peek指定超時時間的多載, 指定訊息抵達佇列的時間。Alternatively, you can specify a time-out for a message to arrive in the queue by using the overload of Peek that specifies a time-out.

下表顯示這個方法是否可在各種工作組模式中使用。The following table shows whether this method is available in various Workgroup modes.

工作組模式Workgroup mode 可用Available
本機電腦Local computer Yes
本機電腦和直接格式名稱Local computer and direct format name Yes
遠端電腦Remote computer No
遠端電腦和直接格式名稱Remote computer and direct format name Yes
另請參閱

Peek(TimeSpan) Peek(TimeSpan) Peek(TimeSpan) Peek(TimeSpan)

傳回而不移除 (窺視) 這個 MessageQueue 所參考佇列中的第一個訊息。Returns without removing (peeks) the first message in the queue referenced by this MessageQueue. Peek() 方法是同步的,因此會封鎖目前的執行緒,直到訊息可以使用或發生指定的逾時為止。The Peek() method is synchronous, so it blocks the current thread until a message becomes available or the specified time-out occurs.

public:
 System::Messaging::Message ^ Peek(TimeSpan timeout);
public System.Messaging.Message Peek (TimeSpan timeout);
member this.Peek : TimeSpan -> System.Messaging.Message
Public Function Peek (timeout As TimeSpan) As Message

參數

timeout
TimeSpan TimeSpan TimeSpan TimeSpan

TimeSpan,指出等待含有訊息之佇列的最長時間。A TimeSpan that indicates the maximum time to wait for the queue to contain a message.

傳回

表示佇列中第一個訊息的 MessageThe Message that represents the first message in the queue.

例外狀況

timeout 參數指定的值無效,可能是 timeout 小於 Zero 或大於 InfiniteTimeoutThe value specified for the timeout parameter is not valid, possibly timeout is less than Zero or greater than InfiniteTimeout.

存取訊息佇列方法時發生錯誤。An error occurred when accessing a Message Queuing method.

範例

下列程式碼範例會使用Peek值為零的方法, 來檢查佇列是否為空的。The following code example uses the Peek method with a time-out of zero to check whether the queue is empty.

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:

   //*************************************************
   // Determines whether a queue is empty. The Peek()
   // method throws an exception if there is no message
   // in the queue. This method handles that exception 
   // by returning true to the calling method.
   //*************************************************
   bool IsQueueEmpty()
   {
      bool isQueueEmpty = false;
      
      // Connect to a queue.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );
      try
      {
         
         // Set Peek to return immediately.
         myQueue->Peek( TimeSpan(0) );
         
         // If an IOTime->Item[Out] was* not thrown, there is a message 
         // in the queue.
         isQueueEmpty = false;
      }
      catch ( MessageQueueException^ e ) 
      {
         if ( e->MessageQueueErrorCode == MessageQueueErrorCode::IOTimeout )
         {
            
            // No message was in the queue.
            isQueueEmpty = true;
         }

         
         // Handle other sources of MessageQueueException.
      }

      
      // Handle other exceptions as necessary.
      // Return true if there are no messages in the queue.
      return isQueueEmpty;
   }

};


//*************************************************
// Provides an entry point into the application.
//         
// This example determines whether a queue is empty.
//*************************************************
int main()
{
   
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;
   
   // Determine whether a queue is empty.
   bool isQueueEmpty = myNewQueue->IsQueueEmpty();
   return 0;
}

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 determines whether a queue is empty.
		//**************************************************

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

			// Determine whether a queue is empty.
			bool isQueueEmpty = myNewQueue.IsQueueEmpty();
						
			return;
		}


		//**************************************************
		// Determines whether a queue is empty. The Peek()
		// method throws an exception if there is no message
		// in the queue. This method handles that exception 
		// by returning true to the calling method.
		//**************************************************
		
		public bool IsQueueEmpty()
		{
			bool isQueueEmpty = false;

			// Connect to a queue.
			MessageQueue myQueue = new MessageQueue(".\\myQueue");

			try
			{
				// Set Peek to return immediately.
				myQueue.Peek(new TimeSpan(0));

				// If an IOTimeout was not thrown, there is a message 
				// in the queue.
				isQueueEmpty = false;
			}

			catch(MessageQueueException e)
			{
				if (e.MessageQueueErrorCode == 
					MessageQueueErrorCode.IOTimeout)
				{
					// No message was in the queue.
					isQueueEmpty = true;
				}

				// Handle other sources of MessageQueueException.
			}

			// Handle other exceptions as necessary.

			// Return true if there are no messages in the queue.
			return isQueueEmpty;

		}
	}
}
Imports System.Messaging



   
    Public Class MyNewQueue


        '
        ' Provides an entry point into the application.
        '		 
        ' This example determines whether a queue is empty.
        '

        Public Shared Sub Main()

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

            ' Determine whether a queue is empty.
            Dim IsQueueEmpty As Boolean = myNewQueue.IsQueueEmpty()
	    if IsQueueEMpty=True Then Console.WriteLine("Empty")
            

            Return

        End Sub


        '
        ' Determines whether a queue is empty. The Peek()
        ' method throws an exception if there is no message
        ' in the queue. This method handles that exception 
        ' by returning true to the calling method.
        '

        Public Function IsQueueEmpty() As Boolean

            'Dim QueueEmpty As Boolean = False

            ' Connect to a queue.
            Dim myQueue As New MessageQueue(".\myQueue")

            Try

                ' Set Peek to return immediately.
                myQueue.Peek(New TimeSpan(0))

                ' If an IOTimeout was not thrown, there is a message 
                ' in the queue.
                'queueEmpty = False

            Catch e As MessageQueueException

                If e.MessageQueueErrorCode = _
                    MessageQueueErrorCode.IOTimeout Then

                    ' No message was in the queue.
                    IsQueueEmpty = True

                End If

                ' Handle other sources of MessageQueueException as necessary.

                ' Handle other exceptions as necessary.

            End Try

            ' Return true if there are no messages in the queue.
            'Return queueEmpty
	    IsQueueEmpty = False

        End Function 'IsQueueEmpty 

End Class 'MyNewQueue

備註

使用此多載來查看佇列, 或等候指定的一段時間, 直到佇列中存在訊息為止。Use this overload to peek a queue, or to wait a specified period of time until a message exists in the queue. 如果訊息已經存在於佇列中, 此方法會立即傳回。The method returns immediately if a message already exists in the queue.

Peek方法會讀取 (但不會移除) 佇列中的第一個訊息。The Peek method reads, but does not remove, the first message from the queue. 因此, 除非較高Peek優先順序的訊息抵達佇列, 否則重複呼叫會傳回相同的訊息。Therefore, repeated calls to Peek return the same message, unless a higher priority message arrives in the queue. 另一方面Receive , 方法會讀取和移除佇列中的第一個訊息。The Receive method, on the other hand, both reads and removes the first message from the queue. 因此, 重複Receive呼叫, 因此會傳回不同的訊息。Repeated calls to Receive, therefore, return different messages.

訊息佇列會根據優先順序和抵達時間來排序佇列中的訊息。Message Queuing orders messages in the queue according to priority and arrival time. 只有在較高的優先順序時, 才會將較新的訊息放在舊版中。A newer message is placed before an older one only if it is of a higher priority.

當目前的執行緒可接受進行封鎖並同時等候訊息到達佇列時,請使用 PeekUse Peek when it is acceptable for the current thread to be blocked while it waits for a message to arrive in the queue. 執行緒將會被封鎖到指定的一段時間, 如果您指出InfiniteTimeout, 則會無限期地封鎖。The thread will be blocked up to the specified period of time, or indefinitely if you indicated InfiniteTimeout. 當您需要應用程式繼續執行而不要等候,請使用非同步的 BeginPeek 方法。If you need the application processing to continue without waiting, use the asynchronous BeginPeek method.

下表顯示這個方法是否可在各種工作組模式中使用。The following table shows whether this method is available in various Workgroup modes.

工作組模式Workgroup mode 可用Available
本機電腦Local computer Yes
本機電腦和直接格式名稱Local computer and direct format name Yes
遠端電腦Remote computer No
遠端電腦和直接格式名稱Remote computer and direct format name Yes
另請參閱

Peek(TimeSpan, Cursor, PeekAction) Peek(TimeSpan, Cursor, PeekAction) Peek(TimeSpan, Cursor, PeekAction)

使用指定的游標傳回而不移除 (窺視) 佇列中的目前或下一則訊息。Returns without removing (peeks) the current or next message in the queue, using the specified cursor. Peek() 方法是同步的,因此會封鎖目前的執行緒,直到訊息可以使用或發生指定的逾時為止。The Peek() method is synchronous, so it blocks the current thread until a message becomes available or the specified time-out occurs.

public:
 System::Messaging::Message ^ Peek(TimeSpan timeout, System::Messaging::Cursor ^ cursor, System::Messaging::PeekAction action);
public System.Messaging.Message Peek (TimeSpan timeout, System.Messaging.Cursor cursor, System.Messaging.PeekAction action);
member this.Peek : TimeSpan * System.Messaging.Cursor * System.Messaging.PeekAction -> System.Messaging.Message

參數

timeout
TimeSpan TimeSpan TimeSpan TimeSpan

TimeSpan,指出等待含有訊息之佇列的最長時間。A TimeSpan that indicates the maximum time to wait for the queue to contain a message.

cursor
Cursor Cursor Cursor Cursor

Cursor,保留訊息佇列中的特定位置。A Cursor that maintains a specific position in the message queue.

action
PeekAction PeekAction PeekAction PeekAction

其中一個 PeekAction 值。One of the PeekAction values. 指出要窺視佇列中的目前訊息,還是下一則訊息。Indicates whether to peek at the current message in the queue, or the next message.

傳回

Message,表示佇列中的訊息。A Message that represents a message in the queue.

例外狀況

action 參數指定 PeekAction.CurrentPeekAction.Next 以外的值。A value other than PeekAction.Current or PeekAction.Next was specified for the action parameter.

cursor 參數為 nullThe cursor parameter is null.

指定給 timeout 參數的值無效。The value specified for the timeout parameter is not valid. 可能是 timeout 小於 Zero 或大於 InfiniteTimeoutPossibly timeout is less than Zero or greater than InfiniteTimeout.

存取訊息佇列方法時發生錯誤。An error occurred when accessing a Message Queuing method.

備註

使用此多載來查看佇列, 或等候指定的一段時間, 直到佇列中存在訊息為止。Use this overload to peek a queue, or to wait a specified period of time until a message exists in the queue. 如果訊息已經存在於佇列中, 此方法會立即傳回。The method returns immediately if a message already exists in the queue.

Peek方法會讀取佇列中的訊息, 但不會將它移除。The Peek method reads, but does not remove, a message from the queue. 另一方面Receive , 方法會從佇列讀取和移除訊息。The Receive method, on the other hand, both reads and removes a message from the queue.

當目前的執行緒可接受進行封鎖並同時等候訊息到達佇列時,請使用 PeekUse Peek when it is acceptable for the current thread to be blocked while it waits for a message to arrive in the queue. 執行緒會被封鎖到指定的一段時間, 如果您指出InfiniteTimeout, 則會無限期地封鎖。The thread is blocked up to the specified period of time, or indefinitely if you indicated InfiniteTimeout. 當您需要應用程式繼續執行而不要等候,請使用非同步的 BeginPeek 方法。If you need the application processing to continue without waiting, use the asynchronous BeginPeek method.

下表顯示這個方法是否可在各種工作組模式中使用。The following table shows whether this method is available in various Workgroup modes.

工作組模式Workgroup mode 可用Available
本機電腦Local computer Yes
本機電腦和直接格式名稱Local computer and direct format name Yes
遠端電腦Remote computer No
遠端電腦和直接格式名稱Remote computer and direct format name Yes
另請參閱

適用於