C#
using System;
using System.Messaging;
using System.Drawing;
using System.IO; namespace MyProject
{ /// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{ /***************************************************/
// Provides an entry point into the application.
//
// This example sends and receives a message from
// a queue.
/***************************************************/ public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue(); // Create a queue on the local computer.
CreateQueue(".\\myQueue"); // Send a message to a queue.
myNewQueue.SendMessage(); // Receive a message from a queue.
myNewQueue.ReceiveMessage(); return;
} /***************************************************/
// Creates a new queue.
/***************************************************/ public static void CreateQueue(string queuePath)
{
try
{
if(!MessageQueue.Exists(queuePath))
{
MessageQueue.Create(queuePath);
}
else
{
Console.WriteLine(queuePath + " already exists.");
}
}
catch (MessageQueueException e)
{
Console.WriteLine(e.Message);
} } /***************************************************/
// Sends an image to a queue, using the BinaryMessageFormatter.
/***************************************************/ public void SendMessage()
{
try{ // Create a new bitmap.
// The file must be in the \bin\debug or \bin\retail folder, or
// you must give a full path to its location.
Image myImage = Bitmap.FromFile("SentImage.bmp"); // Connect to a queue on the local computer.
MessageQueue myQueue = new MessageQueue(".\\myQueue"); Message myMessage = new Message(myImage, new BinaryMessageFormatter()); // Send the image to the queue.
myQueue.Send(myMessage);
}
catch(ArgumentException e)
{
Console.WriteLine(e.Message); } return;
} /***************************************************/
// Receives a message containing an image.
/***************************************************/ public void ReceiveMessage()
{ try
{ // Connect to the a queue on the local computer.
MessageQueue myQueue = new MessageQueue(".\\myQueue"); // Set the formatter to indicate body contains an Order.
myQueue.Formatter = new BinaryMessageFormatter(); // Receive and format the message.
System.Messaging.Message myMessage = myQueue.Receive();
Bitmap myImage = (Bitmap)myMessage.Body; // This will be saved in the \bin\debug or \bin\retail folder.
myImage.Save("ReceivedImage.bmp",System.Drawing.Imaging.ImageFormat.Bmp); } catch (MessageQueueException)
{
// Handle Message Queuing exceptions.
} // Handle invalid serialization format.
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
} catch (IOException e)
{
// Handle file access exceptions.
} // Catch other exceptions as necessary. return;
}
}
}
转载原文:
http://msdn.microsoft.com/zh-cn/beginner/system.messaging.message%28VS.110%29.aspx

C# MyNewQueue 消息队列的更多相关文章

  1. 消息队列——RabbitMQ学习笔记

    消息队列--RabbitMQ学习笔记 1. 写在前面 昨天简单学习了一个消息队列项目--RabbitMQ,今天趁热打铁,将学到的东西记录下来. 学习的资料主要是官网给出的6个基本的消息发送/接收模型, ...

  2. 消息队列 Kafka 的基本知识及 .NET Core 客户端

    前言 最新项目中要用到消息队列来做消息的传输,之所以选着 Kafka 是因为要配合其他 java 项目中,所以就对 Kafka 了解了一下,也算是做个笔记吧. 本篇不谈论 Kafka 和其他的一些消息 ...

  3. .net 分布式架构之业务消息队列

    开源QQ群: .net 开源基础服务  238543768 开源地址: http://git.oschina.net/chejiangyi/Dyd.BusinessMQ ## 业务消息队列 ##业务消 ...

  4. 【原创经验分享】WCF之消息队列

    最近都在鼓捣这个WCF,因为看到说WCF比WebService功能要强大许多,另外也看了一些公司的招聘信息,貌似一些中.高级的程序员招聘,都有提及到WCF这一块,所以,自己也关心关心一下,虽然目前工作 ...

  5. Java消息队列--ActiveMq 实战

    1.下载安装ActiveMQ ActiveMQ官网下载地址:http://activemq.apache.org/download.html ActiveMQ 提供了Windows 和Linux.Un ...

  6. Java消息队列--JMS概述

    1.什么是JMS JMS即Java消息服务(Java Message Service)应用程序接口,是一个Java平台中关于面向消息中间件(MOM)的API,用于在两个应用程序之间,或分布式系统中发送 ...

  7. 消息队列性能对比——ActiveMQ、RabbitMQ与ZeroMQ(译文)

    Dissecting Message Queues 概述: 我花了一些时间解剖各种库执行分布式消息.在这个分析中,我看了几个不同的方面,包括API特性,易于部署和维护,以及性能质量..消息队列已经被分 ...

  8. Netty构建分布式消息队列(AvatarMQ)设计指南之架构篇

    目前业界流行的分布式消息队列系统(或者可以叫做消息中间件)种类繁多,比如,基于Erlang的RabbitMQ.基于Java的ActiveMQ/Apache Kafka.基于C/C++的ZeroMQ等等 ...

  9. Netty构建分布式消息队列实现原理浅析

    在本人的上一篇博客文章:Netty构建分布式消息队列(AvatarMQ)设计指南之架构篇 中,重点向大家介绍了AvatarMQ主要构成模块以及目前存在的优缺点.最后以一个生产者.消费者传递消息的例子, ...

随机推荐

  1. SQL1-(增删改查、常用函数)

    USE flowershopdb --全球唯一标识符(GUID UUID) SELECT NEWID() --增删改查 --INSERT [INTO] <表名> [列名] VALUES & ...

  2. The following classes could not be found: - android.support.v7.internal.widget.ActionBarOverlayLayou解决方案

    如图出现如下的错误的时候,一般都是升级Androdi Studio 后导致的,引入库不全,或者其他 东西缺少,可以如下解决方案: 或者如下的解决方案: 在布局文件的Design界面中,修改原来的App ...

  3. Lavarel(-) windows 部署

    使用 Lavarel 开发完全可以抛开wamp,phpstudy等一键环境.因为lavarel 内置的artisan 整合了php5.4 内置的webserver ,甚至可以使用artisan 命令指 ...

  4. codeforces 632D. Longest Subsequence 筛法

    题目链接 记录小于等于m的数出现的次数, 然后从后往前筛, 具体看代码. #include <iostream> #include <vector> #include < ...

  5. Python GUI开发环境的搭建

    原文:Python GUI开发环境的搭建 最近对Python的开发又来了兴趣,对于Python的开发一直停留在一个表面层的认识,玩的部分比较大. Python的入手简单,语法让人爱不释手,在网络通信方 ...

  6. android 向serverGet和Post请求的两种方式,android向server发送文件,自己组装协议和借助第三方开源

    一个适用于Android平台的第三方和apache的非常多东西类似,仅仅是用于Android上 我在项目里用的是这个 https://github.com/loopj/android-async-ht ...

  7. API和DLL

    API API(Application Programming Interface,应用编程接口)其实就是操作系统留给应用程序的一个调用接口,应用程序通过调用操作系统的 API 而使操作系统去执行应用 ...

  8. //相当于深拷贝一份dataArray。这样才不会改变dataArray本身的值

    //相当于深拷贝一份dataArray.这样才不会改变dataArray本身的值 NSMutableArray* commitDataArray = [NSKeyedUnarchiver unarch ...

  9. jira使用

    JIRA的生产者把JIRA定义为Professional Issue Tracker,即它是一个专业的问题跟踪管理的软件.这里的"问题"对应的英文单词是Issue,所以含义比较广, ...

  10. 浅谈Servlet(二)

    1.forward(请求的转发)和redirect(重定向) 目的:都是为了把一个Servlet的功能,拆分到多个Servlet中,便于后续代码的维护. a.forward(请求转发) (1).如何在 ...