可以使用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. Android Architecture Components

    https://developer.android.com/topic/libraries/architecture/index.html ViewModel 有LiveData Activity 监 ...

  2. Cfree clion windows c语言 socket 网络编程

    server.c #include <stdio.h> #include <winsock2.h> #define SERVER_PORT 5208 //侦听端口 int ma ...

  3. Express+MySQL

    初识NodeJS服务端开发(Express+MySQL) http://www.tuicool.com/articles/JfqYN3I 浅析node连接数据库(express+mysql) http ...

  4. 阿里云ECS购买优惠码

    今天收到了阿里云给我发的邮件,大意是阿里云推荐码限量开放,可享九折优惠! 于是就点击进去申请了一下 申请的优惠码是:C7IYIS有效期至2015-11-30 23:59:59 首次购买包年包月云服务器 ...

  5. Stream01 定义、迭代、操作、惰性求值、创建流、并行流、收集器、stream运行机制

    1 Stream Stream 是 Java 8 提供的一系列对可迭代元素处理的优化方案,使用 Stream 可以大大减少代码量,提高代码的可读性并且使代码更易并行. 2 迭代 2.1 需求 随机创建 ...

  6. 37.ROUND() 函数

    ROUND() 函数 ROUND 函数用于把数值字段舍入为指定的小数位数. SQL ROUND() 语法 SELECT ROUND(column_name,decimals) FROM table_n ...

  7. wordpress中add_action和add_filter

    add_action( string $tag, callable $function_to_add, int $priority = 10,int $accepted_args = 1 ) 官网是这 ...

  8. hibernate mapping文件中 xmlns会导致linq to xml 查询不到对应的节点

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. jqgrid控件列分组

    <%-- builed by manage.aspx.cmt [ver:2014.48.11] at 2014/10/11 16:48:33 --%> <%@ Page Langua ...

  10. Appium混合应用测试

    Appium测试混合应用 混合应用即是原生应用中间混着html页面,需要在两种类型的页面之间跳转. 测试Android混合应用 前期设置 4.4以下版本使用automationName:Selendr ...