Gets or sets the time limit for the message to be retrieved from the target queue.
[Visual Basic] Overridable Public Property TimeToBeReceived As TimeSpan [C#] public TimeSpan TimeToBeReceived {virtual get; virtual set;} [C++] public: __property virtual TimeSpan get_TimeToBeReceived(); public: __property virtual void set_TimeToBeReceived(TimeSpan); [JScript] public function get TimeToBeReceived() : TimeSpan; public function set TimeToBeReceived(TimeSpan);
The time limit, in seconds, for the message to be retrieved from the target queue. The default is InfiniteTimeout.
Exception Type | Condition |
---|---|
InvalidOperationException | The message queue is filtered not to read the TimeToBeReceived property. |
ArgumentException | The value specified for TimeToBeReceived is invalid. It may represent a negative number. |
TimeToBeReceived provides access to the MaxTimeToReceive property of the Message Queuing MSMQMessage object.
The time limit for the message to be retrieved from the target queue includes the time spent getting to the queue, and the time spent waiting in the queue before the message is retrieved by an application.
If the TimeToBeReceived interval expires before the message is removed from the queue, Message Queuing discards the message and sends it to the dead-letter queue if the message's UseDeadLetterQueue property is set to true.
Message Queuing can also send a negative acknowledgment message to the sending application if the message's AcknowledgeType property is set accordingly and the message is not retrieved before the timeout expires.
InfiniteTimeout is the only negative integer value that can be used for a timeout. If you attempt to specify any other negative value for TimeToBeReceived or TimeToReachQueue, an ArgumentException exception will be thrown. You should catch this exception in your code when setting the TimeToBeReceived.
The following example creates an empty message. The example populates the Message with a string Body, sets the TimeToBeReceived and TimeToReachQueue properties, and then sends the message to a queue. It assumes there is a queue on the computer "myComputer" with the name "myQueue".
Import the System.Messaging namespace for this example.
[Visual Basic]
Private Sub CreateMessage() 'Declare a message and message queue Dim msg As Message Dim mq As MessageQueue 'Instantiate an empty message object msg = New Message 'Instantiate a new MessageQueue object mq = New MessageQueue("myComputer\myQueue") 'Set selected message properties. msg.TimeToBeReceived = New TimeSpan(1000) msg.TimeToReachQueue = New TimeSpan(1000) msg.Body = "New Message Body" 'Send the message to the queue. mq.Send(msg) End Sub
Message Class | Message Members | System.Messaging Namespace | TimeToReachQueue | InfiniteTimeout | UseTracing | Recoverable