本文整理汇总了C#中System.Messaging.MessageQueue.MessageReadPropertyFilter属性的典型用法代码示例。如果您正苦于以下问题:C# MessageQueue.MessageReadPropertyFilter属性的具体用法?C# MessageQueue.MessageReadPropertyFilter怎么用?C# MessageQueue.MessageReadPropertyFilter使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Messaging.MessageQueue
的用法示例。
在下文中一共展示了MessageQueue.MessageReadPropertyFilter属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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 retrieves specific groups of Message
// properties.
//**************************************************
public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Retrieve specific sets of Message properties.
myNewQueue.RetrieveDefaultProperties();
myNewQueue.RetrieveAllProperties();
myNewQueue.RetrieveSelectedProperties();
return;
}
//**************************************************
// Retrieves the default properties for a Message.
//**************************************************
public void RetrieveDefaultProperties()
{
// Connect to a message queue.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
// Specify to retrieve the default properties only.
myQueue.MessageReadPropertyFilter.SetDefaults();
// Set the formatter for the Message.
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});
// Receive the first message in the queue.
Message myMessage = myQueue.Receive();
// Display selected properties.
Console.WriteLine("Label: " + myMessage.Label);
Console.WriteLine("Body: " + (String)myMessage.Body);
return;
}
//**************************************************
// Retrieves all properties for a Message.
//**************************************************
public void RetrieveAllProperties()
{
// Connect to a message queue.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
// Specify to retrieve all properties.
myQueue.MessageReadPropertyFilter.SetAll();
// Set the formatter for the Message.
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});
// Receive the first message in the queue.
Message myMessage = myQueue.Receive();
// Display selected properties.
Console.WriteLine("Encryption algorithm: " +
myMessage.EncryptionAlgorithm.ToString());
Console.WriteLine("Body: " + (String)myMessage.Body);
return;
}
//**************************************************
// Retrieves application-specific properties for a
// Message.
//**************************************************
public void RetrieveSelectedProperties()
{
// Connect to a message queue.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
// Specify to retrieve selected properties.
MessagePropertyFilter myFilter = new
MessagePropertyFilter();
myFilter.ClearAll();
// The following list is a random subset of available properties.
myFilter.Body = true;
myFilter.Label = true;
myFilter.MessageType = true;
myFilter.Priority = true;
myQueue.MessageReadPropertyFilter = myFilter;
// Set the formatter for the Message.
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});
// Receive the first message in the queue.
Message myMessage = myQueue.Receive();
// Display selected properties.
Console.WriteLine("Message type: " +
myMessage.MessageType.ToString());
Console.WriteLine("Priority: " +
myMessage.Priority.ToString());
return;
}
}
}