RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:9:30-18:00
你可能遇到了下面的问题
关闭右侧工具栏
Messagqueue发送图片
  • 作者:zhaozj
  • 发表时间:2020-12-23 10:54
  • 来源:未知

摘自msdn

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());