可以使用Windows自带计划任务执行Receive操作。
控制面板=>管理工具 计划任务 =>创建计划任务 step : http://www.2cto.com/kf/201402/277337.html using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Messaging;
using System.Text;
using System.Threading;
using System.Threading.Tasks; namespace ConsoleApplication26
{
class Program
{
private static int PostCoount { get; set; }
private static MessageQueue _queue; private static readonly string _queuePath = ".\\private$\\MSMQDemo";
private static MessageQueue Queue
{
get
{
if (_queue == null)
{
_queue = new MessageQueue(_queuePath)
{
Formatter = new XmlMessageFormatter(new Type[] { typeof(User) })
}; Debug.WriteLine("Connect To " + _queuePath + " Done!");
} return _queue;
}
}
static void Main(string[] args)
{ //Thread[] threads = new Thread[200];
//for (int i = 0; i < 200; i++)
//{ // ParameterizedThreadStart threadStart = new ParameterizedThreadStart(Send);
// Thread thread = new Thread(threadStart) { IsBackground = true };
// threads[i] = thread; // User user = new User() { ID = 1, Phone = "15689", Name = "张三" };
// thread.Start(user);
//} User u = new User();
u.Name = "ls";
u.Phone = ""; Send(u); //ThreadStart ttStart = new ThreadStart(Receive);
//Thread t = new Thread(ttStart);
//t.IsBackground = true;
//t.Start(); /*挂起Supend()*/
//for (int i = 0; i < PostCoount; i++)
//{
//while (true)
//{
// Receive();
//} //}
/*恢复*/ Console.WriteLine("完成"); Console.ReadLine(); } public static int Add(User user)
{
string sql = @"
insert into [User] values ('" + user.Phone + "','" + user.Name + "') "; string conStr = "data source=192.168.1.10;initial catalog=xiaocainiao;user id=guakao;password=wrx.362114";
int i = ; using (SqlConnection connect = new SqlConnection(conStr))
{
connect.Open();
SqlCommand cmd = new SqlCommand(sql, connect);
cmd.ExecuteNonQuery();
i++;
} return i;
} /// <summary>
/// Send
/// </summary>
private static void Send(object user)
{ for (var i = ; i <= ; i++)
{
//var message = new Message();
System.Messaging.Message message = new System.Messaging.Message();
message.Body = (User)user;
message.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(User) });
Queue.Send(message); }
} /// <summary>
/// Receive
/// </summary>
private static void Receive()
{
//MessageQueue myQueue = new MessageQueue(".\\private$\\MSMQDemo");
//myQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(User) }); //从队列中接收消息
Message myMessage = Queue.Receive();
myMessage.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(User) });
User context = myMessage.Body as User; //获取消息的内容
Add(context); }
}
}

消息队列 简单demo的更多相关文章

  1. Linux 进程间通信(posix消息队列 简单)实例

    Linux 进程间通信(posix消息队列 简单)实例 详情见: http://www.linuxidc.com/Linux/2011-10/44828.htm 编译: gcc -o consumer ...

  2. redis消息队列简单应用

    消息队列出现的原因 随着互联网的高速发展,门户网站.视频直播.电商领域等web应用中,高并发.大数据已经成为基本的标识.淘宝双11.京东618.各种抢购.秒杀活动.以及12306的春运抢票等,他们这些 ...

  3. 使用java实现阿里云消息队列简单封装

    一.前言 最近公司有使用阿里云消息队列的需求,为了更加方便使用,本人用了几天时间将消息队列封装成api调用方式以方便内部系统的调用,现在已经完成,特此记录其中过程和使用到的相关技术,与君共勉. 现在阿 ...

  4. C# Queue与RabbitMQ的爱恨情仇(文末附源码):Q与MQ消息队列简单应用(二)

    上一章我们讲了队列( Queue),这一章我们讲Message Queue消息队列,简称MQ. 定义: MQ是MessageQueue,消息队列的简称(是流行的开源消息队列系统,利用erlang语言开 ...

  5. node事件循环和消息队列简单分析

    node的好处毋庸置疑,事件驱动,异步非阻塞I/O,以及处理高并发的能力深入人心,因此大家喜欢用node做一些小型后台服务或者作为中间层和其他服务配合完成一些大型应用场景. 什么是异步? 异步和同步应 ...

  6. 【转】MSMQ 微软消息队列 简单 示例

    MSMQ它的实现原理是:消息的发送者把自己想要发送的信息放入一个容器中(我们称之为Message),然后把它保存至一个系统公用空间的消息队列(Message Queue)中:本地或者是异地的消息接收程 ...

  7. Redis 应用只 消息队列 简单实现(生产者 消费者模式)

    运行效果:

  8. System V IPC 之消息队列

    消息队列和共享内存.信号量一样,同属 System V IPC 通信机制.消息队列是一系列连续排列的消息,保存在内核中,通过消息队列的引用标识符来访问.使用消息队列的好处是对每个消息指定了特定消息类型 ...

  9. rabbitMQ消息队列原理

    MQ:Message Queue,消息队列,是一种应用程序对应用程序的通信方法:应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们. 1      rabbitMQ入 ...

随机推荐

  1. 2&nbsp;时间管理和内存管理

    时间管理 uC/OS-II的时间管理是通过定时中断来实现的,该定时中断一般为10毫秒或100毫秒发生一次(这个时间片段是OS的作者推荐的,大家可以参考邵贝贝翻译的<嵌入式实时操作系统ucos-I ...

  2. 在VMware中为Red Hat配置静态ip并可访问网络-Windows下的VMware

    首先确保虚拟网卡(VMware Network Adapter VMnet8)是开启的,然后在windows的命令行里输入“ipconfig /all”,找到VMware Network Adapte ...

  3. libevent源码深度剖析九

    libevent源码深度剖析九 ——集成定时器事件 张亮 现在再来详细分析libevent中I/O事件和Timer事件的集成,与Signal相比,Timer事件的集成会直观和简单很多.Libevent ...

  4. mfs监控

    web gui 监控 gui_info.jpg (143.72 KB, 下载次数: 83) gui_most.jpg (209.36 KB, 下载次数: 82) gui_master_info.jpg ...

  5. 公共技术点之 Java 反射 Reflection

    本文摘录地址: http://codekk.com/open-source-project-analysis/detail/Android/Mr.Simple/%E5%85%AC%E5%85%B1%E ...

  6. 720. Longest Word in Dictionary 能连续拼接出来的最长单词

    [抄题]: Given a list of strings words representing an English Dictionary, find the longest word in wor ...

  7. 5-有道爬虫demo(post)

    爬取有道页面,实现中文翻译成英文: #_*_ coding: utf-8 _*_ ''' Created on 2018-7-12 @author: sss 功能:爬取有道翻译 ''' import ...

  8. 4-fiddler抓包中文乱码:

    接受到的html被压缩了,要解压,在工具栏有decode

  9. 面试题:java实例变量,局部变量,类变量 背1

    一.实例变量 也叫对象变量.类成员变量:从属于类由类生成对象时,才分配存储空间,各对象间的实例变量互不干扰,能通过对象的引用来访问实例变量.但在Java多线程中,实例变量是多个线程共享资源,要注意同步 ...

  10. ROS naviagtion analysis: costmap_2d--StaticLayer

    博客转载自:https://blog.csdn.net/u013158492/article/details/50493246 从UML中能够看到,StaticLayer主要是在实现Layer层要求实 ...