У меня есть программа на C #, которая пытается отправить в мою собственную локальную очередь сообщений Windows. Я установил очередь сообщений и в отчаянии дал все права доступа «Все» как в самой очереди сообщений, так и в общей очереди, в которую я пытаюсь записать. У меня есть форма, которая имеет два текстовых поля и две кнопки. Одна пара для отправки и другая пара для получения. Я нажимаю отправить и не получаю ошибок, он может обнаружить, что на самом деле существует очередь сообщений с таким именем. Но метод send, похоже, отключается, фактически не помещая его в очередь. Спасибо за любую помощь! Вот код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Messaging;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public MessageQueue myNewPublicQueue;
private static object lockObject = new object();
/// <summary>
///
/// </summary>
public Form1()
{
InitializeComponent();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttoSend_Click(object sender, EventArgs e)
{
if (MessageQueue.Exists(@".\queuename"))
{
myNewPublicQueue = new System.Messaging.MessageQueue(@".\queuename");
System.Messaging.Message mm = new System.Messaging.Message();
mm.Body = textBoxSend.Text;
mm.Label = "First Test Message";
myNewPublicQueue.Send(mm);
}
}
private void buttonGet_Click(object sender, EventArgs e)
{
myNewPublicQueue.ReceiveCompleted += new ReceiveCompletedEventHandler(queue_ReceiveCompleted);
// Start listening.
myNewPublicQueue.BeginReceive();
}
private void queue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
{
lock (lockObject)
{
// The message is plain text.
string text = (string)e.Message.Body;
Console.WriteLine("Message received: " + text);
textBoxGet.Text = text;
}
// Listen for the next message.
myNewPublicQueue.BeginReceive();
}
public enum MessageType
{
MESSAGE_TYPE_PLAIN_TEXT = 0,
MESSAGE_TYPE_HELLO_WORLD = 1
};
private void Form1_Load(object sender, EventArgs e)
{
}
}
}