可以使用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. linux驱动模块编译(初学者)

    inux 模块编译步骤(转) 本文将直接了当的带你进入linux的模块编译.当然在介绍的过程当中,我也会添加一些必要的注释,以便初学者能够看懂.之所以要写这篇文章,主要是因为从书本上学的话,可能要花更 ...

  2. Idea的基本介绍

    Idea的基本介绍 Idea一般是作为一个Java和Scala的开发工具来使用的,它的使用方法和Eclipse有一些不同,这里记录以下一些基本点. 1.创建项目 创建一个新项目的时候,用户必须选择一个 ...

  3. dom方式解析xml文件的步骤

    使用java类即可

  4. libevent源码深度剖析七

    libevent源码深度剖析七 ——事件主循环 张亮 现在我们已经初步了解了libevent的Reactor组件——event_base和事件管理框架,接下来就是libevent事件处理的中心部分 — ...

  5. 小程序为什么脚本内不能使用window等对象

    小程序(应用号)内不能使用window等对象. 页面的脚本逻辑在是在JsCore中运行,JsCore是一个没有窗口对象的环境,所以不能再脚本中使用window,也无法在脚本中操作组件.

  6. Python04 range()方法的使用、turtle.textinput()方法和write()的使用、turtle.numinput()的使用

    1 range() 方法的使用 1.1 range方法介绍 range方法会返回一个range类型的对象,该对象会根据range方法的参数产生一些列整型数据 技巧01:range方法有三个参数,第一个 ...

  7. ROS naviagtion analysis: costmap_2d--ObstacleLayer

    博客转载自:https://blog.csdn.net/u013158492/article/details/50493676 构造函数 ObstacleLayer() { costmap_ = NU ...

  8. 【转载】Python BeautifulSoup匹配字符串

    作者:鸡仔说链接:https://www.jianshu.com/p/ceb99aed4b2e來源:简书 BeautifulSoup中可以通过name和attrs去定位名称和属性,以找到特定的html ...

  9. php连接redis

    $redis = new Redis(); $redis->connect();

  10. JavaEE互联网轻量级框架整合开发(书籍)阅读笔记(2):SSM+Redis概念理解

    一.SSM+Redis的结构图 在Java互联网中,以Spring+SpringMVC+MyBatis(SSM)作为主流框架,SSM+Redis的结构图如下: 二.下面介绍它们各自承担的功能: 1.S ...