Click here to Skip to main content
15,895,084 members
Articles / Mobile Apps / Windows Mobile

Windows Mobile Interprocess Communication with Message Queues in .NET

Rate me:
Please Sign up or sign in to vote.
4.81/5 (17 votes)
15 Nov 2008CPOL11 min read 83.7K   1.1K   41  
Wrapper demonstrating the use of native message queues within managed code.
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using J2i.Net.NamedObjects;

namespace J2i.Net.WriterClient
{
    public partial class Form1 : Form
    {
        const string QueueEndpointName = "J2i.Net.ReaderWriterTestQueue";
        const int maxItems = 8;
        const int maxMessageSize = 1024;

        string _helpFilePath ;

        MessageQueueWriter _writer = null;

        string HelpFilePath
        {
            get
            {
                if (_helpFilePath == null)
                {
                    _helpFilePath = Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.GetModules()[0].FullyQualifiedName), "J2i.Net.WriterClient.Htlp.html");
                }
                return _helpFilePath;
            }
        }


        public Form1()
        {
            InitializeComponent();
            _writer = new MessageQueueWriter(QueueEndpointName, maxItems, maxMessageSize);

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void miExit_Click(object sender, EventArgs e)
        {
            _writer.Dispose();
            this.Close();
        }

        private void cmdSend_Click(object sender, EventArgs e)
        {
            QueueResult result =  _writer.Write(this.txtMessage.Text,2000);
            if (result == QueueResult.OK)
            {
                txtMessage.Text = String.Empty;
                statusBar.Text = "Message Send.";
            }
            else
            {
                statusBar.Text = String.Format("Message not sent:{0}", result);
            }
            UpdateQueueInfo();
            txtMessage.Focus();
        }

        void UpdateQueueInfo()
        {
            MessageQueueInfo mqinfo = _writer.GetMessageQueueInfo();
            this.lvQueueInfo.Items.Clear();

            ListViewItem item;

            item = new ListViewItem(new string[] { "Number of Writers", mqinfo.NumWriters.ToString() });
            lvQueueInfo.Items.Add(item);

            item = new ListViewItem(new string[] { "Number of Readers", mqinfo.NumReaders.ToString() });
            lvQueueInfo.Items.Add(item);

            item = new ListViewItem(new string[] { "Max Message Count", mqinfo.dwMaxQueueMessages.ToString() });
            lvQueueInfo.Items.Add(item);

            item = new ListViewItem(new string[] { "Max Messages", mqinfo.dwMaxMessages.ToString() });
            lvQueueInfo.Items.Add(item);

            item = new ListViewItem(new string[] { "Current Messages", mqinfo.dwCurrentMessages.ToString() });
            lvQueueInfo.Items.Add(item);

        }

        private void miQueueInfo_Click(object sender, EventArgs e)
        {
            UpdateQueueInfo();
        }

        private void Form1_HelpRequested(object sender, HelpEventArgs hlpevent)
        {
            Help.ShowHelp(this, HelpFilePath);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
I attended Southern Polytechnic State University and earned a Bachelors of Science in Computer Science and later returned to earn a Masters of Science in Software Engineering. I've largely developed solutions that are based on a mix of Microsoft technologies with open source technologies mixed in. I've got an interest in astronomy and you'll see that interest overflow into some of my code project articles from time to time.



Twitter:@j2inet

Instagram: j2inet


Comments and Discussions