获取或设置队列的路径。设置 Path 会导致 MessageQueue 指向新队列。
命名空间:System.Messaging
程序集:System.Messaging(在 system.messaging.dll 中)
![](https://i-blog.csdnimg.cn/blog_migrate/824674f6b2f99367c341175f68d5f007.png)
Public Property Path As String
Dim instance As MessageQueue Dim value As String value = instance.Path instance.Path = value
public string Path { get; set; }
public: property String^ Path { String^ get (); void set (String^ value); }
/** @property */ public String get_Path () /** @property */ public void set_Path (String value)
public function get Path () : String public function set Path (value : String)
属性值
由 MessageQueue 引用的队列。默认值取决于所使用的 MessageQueue 构造函数;它或者是 空引用(在 Visual Basic 中为 Nothing),或者是由构造函数的 path 参数指定的。![](https://i-blog.csdnimg.cn/blog_migrate/824674f6b2f99367c341175f68d5f007.png)
异常类型 | 条件 |
---|---|
路径无效,可能是因为语法无效。 |
![](https://i-blog.csdnimg.cn/blog_migrate/824674f6b2f99367c341175f68d5f007.png)
Path 属性的语法取决于它指向的队列类型,如下表所示。
队列类型 | 语法 |
---|---|
公共队列 | MachineName/QueueName |
专用队列 | MachineName/Private$/QueueName |
日记队列 | MachineName/QueueName/Journal$ |
计算机日记队列 | MachineName/Journal$ |
计算机死信队列 | MachineName/Deadletter$ |
计算机事务性死信队列 | MachineName/XactDeadletter$ |
使用“.”表示本地计算机。
MachineName、Path 和 QueueName 属性是相关的。更改 MachineName 属性会导致 Path 属性更改。它是从新的 MachineName 和 QueueName 生成的。更改 Path(例如,使用格式名语法)会将 MachineName 和 QueueName 属性重置为引用新队列。
或者,可以使用 FormatName 或 Label 描述队列路径,如下表所示。
引用 | 语法 | 示例 |
---|---|---|
格式名 | FormatName: [ format name ] | FormatName:Public= 5A5F7535-AE9A-41d4-935C-845C2AFF7112 |
标签 | Label: [ label ] | Label: TheLabel |
如果发送消息时对 Path 属性使用标签语法,则当 Label 不唯一时将引发异常。
若要脱机工作,必须在第一个表中使用格式名语法,而不使用友好名称语法。否则,由于主域控制器(Active Directory 的驻留位置)无法用于解析格式名的路径,将发生异常。
设置新路径会关闭消息队列并释放所有句柄。
下表显示此属性在不同的工作组模式中是否可用。
工作组模式 | 可用 |
---|---|
本地计算机 | 是 |
本地计算机 + 直接格式名 | 是 |
远程计算机 | 是 |
远程计算机 + 直接格式名 | 是 |
Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE 平台说明: 因为设备上不支持 Active Directory,所以 .NET Compact Framework 无法确定远程队列是否是事务性的。若要将消息发送到远程事务队列,请将 ;XACTONLY 追加到 Path 属性。有关更多信息,请参见 .NET Compact Framework 中的 MSMQ。
![](https://i-blog.csdnimg.cn/blog_migrate/824674f6b2f99367c341175f68d5f007.png)
下面的代码示例使用各种路径名语法类型创建新的 MessageQueue 对象。在每种情况下,它将消息发送到路径在构造函数中定义的队列。
Imports System Imports System.Messaging Public Class MyNewQueue ' Provides an entry point into the application. ' ' This example demonstrates several ways to set ' a queue's path. Public Shared Sub Main() ' Create a new instance of the class. Dim myNewQueue As New MyNewQueue() myNewQueue.SendPublic() myNewQueue.SendPrivate() myNewQueue.SendByLabel() myNewQueue.SendByFormatName() myNewQueue.MonitorComputerJournal() myNewQueue.MonitorQueueJournal() myNewQueue.MonitorDeadLetter() myNewQueue.MonitorTransactionalDeadLetter() Return End Sub 'Main ' References public queues. Public Sub SendPublic() Dim myQueue As New MessageQueue("./myQueue") myQueue.Send("Public queue by path name.") Return End Sub 'SendPublic ' References private queues. Public Sub SendPrivate() Dim myQueue As New MessageQueue("./Private$/myQueue") myQueue.Send("Private queue by path name.") Return End Sub 'SendPrivate ' References queues by label. Public Sub SendByLabel() Dim myQueue As New MessageQueue("Label:TheLabel") myQueue.Send("Queue by label.") Return End Sub 'SendByLabel ' References queues by format name. Public Sub SendByFormatName() Dim myQueue As New _ MessageQueue("FormatName:Public=" + _ "5A5F7535-AE9A-41d4-935C-845C2AFF7112") myQueue.Send("Queue by format name.") Return End Sub 'SendByFormatName ' References computer journal queues. Public Sub MonitorComputerJournal() Dim computerJournal As New MessageQueue("./Journal___FCKpd___6quot;) While True Dim journalMessage As Message = _ computerJournal.Receive() ' Process the journal message. End While Return End Sub 'MonitorComputerJournal ' References queue journal queues. Public Sub MonitorQueueJournal() Dim queueJournal As New _ MessageQueue("./myQueue/Journal___FCKpd___6quot;) While True Dim journalMessage As Message = _ queueJournal.Receive() ' Process the journal message. End While Return End Sub 'MonitorQueueJournal ' References dead-letter queues. Public Sub MonitorDeadLetter() Dim deadLetter As New MessageQueue("./DeadLetter___FCKpd___6quot;) While True Dim deadMessage As Message = deadLetter.Receive() ' Process the dead-letter message. End While Return End Sub 'MonitorDeadLetter ' References transactional dead-letter queues. Public Sub MonitorTransactionalDeadLetter() Dim TxDeadLetter As New MessageQueue("./XactDeadLetter___FCKpd___6quot;) While True Dim txDeadLetterMessage As Message = _ TxDeadLetter.Receive() ' Process the transactional dead-letter message. End While Return End Sub 'MonitorTransactionalDeadLetter End Class 'MyNewQueue
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 demonstrates several ways to set // a queue's path. //************************************************** public static void Main() { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); myNewQueue.SendPublic(); myNewQueue.SendPrivate(); myNewQueue.SendByLabel(); myNewQueue.SendByFormatName(); myNewQueue.MonitorComputerJournal(); myNewQueue.MonitorQueueJournal(); myNewQueue.MonitorDeadLetter(); myNewQueue.MonitorTransactionalDeadLetter(); return; } // References public queues. public void SendPublic() { MessageQueue myQueue = new MessageQueue(".//myQueue"); myQueue.Send("Public queue by path name."); return; } // References private queues. public void SendPrivate() { MessageQueue myQueue = new MessageQueue(".//Private$//myQueue"); myQueue.Send("Private queue by path name."); return; } // References queues by label. public void SendByLabel() { MessageQueue myQueue = new MessageQueue("Label:TheLabel"); myQueue.Send("Queue by label."); return; } // References queues by format name. public void SendByFormatName() { MessageQueue myQueue = new MessageQueue("FormatName:Public=5A5F7535-AE9A-41d4" + "-935C-845C2AFF7112"); myQueue.Send("Queue by format name."); return; } // References computer journal queues. public void MonitorComputerJournal() { MessageQueue computerJournal = new MessageQueue(".//Journal___FCKpd___7quot;); while(true) { Message journalMessage = computerJournal.Receive(); // Process the journal message. } } // References queue journal queues. public void MonitorQueueJournal() { MessageQueue queueJournal = new MessageQueue(".//myQueue//Journal___FCKpd___7quot;); while(true) { Message journalMessage = queueJournal.Receive(); // Process the journal message. } } // References dead-letter queues. public void MonitorDeadLetter() { MessageQueue deadLetter = new MessageQueue(".//DeadLetter___FCKpd___7quot;); while(true) { Message deadMessage = deadLetter.Receive(); // Process the dead-letter message. } } // References transactional dead-letter queues. public void MonitorTransactionalDeadLetter() { MessageQueue TxDeadLetter = new MessageQueue(".//XactDeadLetter___FCKpd___7quot;); while(true) { Message txDeadLetter = TxDeadLetter.Receive(); // Process the transactional dead-letter message. } } } }
#using <system.dll> #using <system.messaging.dll> using namespace System; using namespace System::Messaging; ref class MyNewQueue { public: // References public queues. void SendPublic() { MessageQueue^ myQueue = gcnew MessageQueue( ".//myQueue" ); myQueue->Send( "Public queue by path name." ); return; } // References private queues. void SendPrivate() { MessageQueue^ myQueue = gcnew MessageQueue( ".//Private$//myQueue" ); myQueue->Send( "Private queue by path name." ); return; } // References queues by label. void SendByLabel() { MessageQueue^ myQueue = gcnew MessageQueue( "Label:TheLabel" ); myQueue->Send( "Queue by label." ); return; } // References queues by format name. void SendByFormatName() { MessageQueue^ myQueue = gcnew MessageQueue( "FormatName:Public=5A5F7535-AE9A-41d4 -935C-845C2AFF7112" ); myQueue->Send( "Queue by format name." ); return; } // References computer journal queues. void MonitorComputerJournal() { MessageQueue^ computerJournal = gcnew MessageQueue( ".//Journal___FCKpd___8quot; ); while ( true ) { Message^ journalMessage = computerJournal->Receive(); // Process the journal message. } } // References queue journal queues. void MonitorQueueJournal() { MessageQueue^ queueJournal = gcnew MessageQueue( ".//myQueue//Journal___FCKpd___8quot; ); while ( true ) { Message^ journalMessage = queueJournal->Receive(); // Process the journal message. } } // References dead-letter queues. void MonitorDeadLetter() { MessageQueue^ deadLetter = gcnew MessageQueue( ".//DeadLetter___FCKpd___8quot; ); while ( true ) { Message^ deadMessage = deadLetter->Receive(); // Process the dead-letter message. } } // References transactional dead-letter queues. void MonitorTransactionalDeadLetter() { MessageQueue^ TxDeadLetter = gcnew MessageQueue( ".//XactDeadLetter___FCKpd___8quot; ); while ( true ) { Message^ txDeadLetter = TxDeadLetter->Receive(); // Process the transactional dead-letter message. } } }; //************************************************* // Provides an entry point into the application. // // This example demonstrates several ways to set // a queue's path. //************************************************* int main() { // Create a new instance of the class. MyNewQueue^ myNewQueue = gcnew MyNewQueue; myNewQueue->SendPublic(); myNewQueue->SendPrivate(); myNewQueue->SendByLabel(); myNewQueue->SendByFormatName(); myNewQueue->MonitorComputerJournal(); myNewQueue->MonitorQueueJournal(); myNewQueue->MonitorDeadLetter(); myNewQueue->MonitorTransactionalDeadLetter(); return 0; }
package MyProject; import System.*; import System.Messaging.*; /// <summary> /// Provides a container class for the example. /// </summary> public class MyNewQueue { //************************************************** // Provides an entry point into the application. // // This example demonstrates several ways to set // a queue's path. //************************************************** public static void main(String[] args) { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); myNewQueue.SendPublic(); myNewQueue.SendPrivate(); myNewQueue.SendByLabel(); myNewQueue.SendByFormatName(); myNewQueue.MonitorComputerJournal(); myNewQueue.MonitorQueueJournal(); myNewQueue.MonitorDeadLetter(); myNewQueue.MonitorTransactionalDeadLetter(); return; } //main // References public queues. public void SendPublic() { MessageQueue myQueue = new MessageQueue(".//myQueue"); myQueue.Send("Public queue by path name."); return; } //SendPublic // References private queues. public void SendPrivate() { MessageQueue myQueue = new MessageQueue(".//Private$//myQueue"); myQueue.Send("Private queue by path name."); return; } //SendPrivate // References queues by label. public void SendByLabel() { MessageQueue myQueue = new MessageQueue("Label:TheLabel"); myQueue.Send("Queue by label."); return; } //SendByLabel // References queues by format name. public void SendByFormatName() { MessageQueue myQueue = new MessageQueue("FormatName:Public=5A5F7535-AE9A-41d4" + "-935C-845C2AFF7112"); myQueue.Send("Queue by format name."); return; } //SendByFormatName // References computer journal queues. public void MonitorComputerJournal() { MessageQueue computerJournal = new MessageQueue(".//Journal___FCKpd___9quot;); while (true) { Message journalMessage = computerJournal.Receive(); // Process the journal message. } } //MonitorComputerJournal // References queue journal queues. public void MonitorQueueJournal() { MessageQueue queueJournal = new MessageQueue(".//myQueue//Journal___FCKpd___9quot;); while (true) { Message journalMessage = queueJournal.Receive(); // Process the journal message. } } //MonitorQueueJournal // References dead-letter queues. public void MonitorDeadLetter() { MessageQueue deadLetter = new MessageQueue(".//DeadLetter___FCKpd___9quot;); while (true) { Message deadMessage = deadLetter.Receive(); // Process the dead-letter message. } } //MonitorDeadLetter // References transactional dead-letter queues. public void MonitorTransactionalDeadLetter() { MessageQueue objTxDeadLetter = new MessageQueue(".//XactDeadLetter___FCKpd___9quot;); while (true) { Message txDeadLetter = objTxDeadLetter.Receive(); // Process the transactional dead-letter message. } } //MonitorTransactionalDeadLetter } //MyNewQueue
![](https://i-blog.csdnimg.cn/blog_migrate/824674f6b2f99367c341175f68d5f007.png)
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见。
![](https://i-blog.csdnimg.cn/blog_migrate/824674f6b2f99367c341175f68d5f007.png)
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
![](https://i-blog.csdnimg.cn/blog_migrate/824674f6b2f99367c341175f68d5f007.png)