WPF 之消息队列
来源:互联网 发布:mysql 主主 维护 编辑:程序博客网 时间:2024/05/16 08:30
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace BaseStationTool.Common
{
/// <summary>
/// 消息
/// </summary>
public class MyMessage
{
public volatile object Parameter;
public volatile object father;
public MyMessage(object sender, object Parameter)
{
this.father = sender;
this.Parameter = Parameter;
}
}
/// <summary>
/// 消息队列
/// </summary>
public partial class QueueMessages
{
private volatile ManualResetEvent Event = new ManualResetEvent(false);
private volatile Queue<MyMessage> Messages = new Queue<MyMessage>();
public int Count()
{
return Messages.Count;
}
public void PushMessage(object sender, object obj)
{
MyMessage message = new MyMessage(sender, obj);
Messages.Enqueue(message);
Event.Set();
}
public MyMessage PopMessage()
{
return Messages.Dequeue();
}
public bool waitCommand(int over)
{
if (over != 0)
{
if (Event.WaitOne(over, true))
{
Event.Reset();
return true;
}
else
return false;
}
else
{
Event.WaitOne();
Event.Reset();
return true;
}
}
}
}
/*
用例 消息处理 用后台线程作为处理
在APP类里面 运用
public static volatile QueueMessages QueMessages = new QueueMessages(); /*静态类*/
Thread threadCommand = new Thread(commandThread);
threadCommand.Start();
/// <summary>
/// 后台 线程
/// </summary>
private void commandThread()
{
DateTime timeEnd;
while (true)
{
QueMessages.waitCommand(0);
mutex.WaitOne();
while (QueMessages.Count() != 0)
{
MyMessage message = QueMessages.PopMessage();
string str = message.Parameter.ToString();
Console.WriteLine(message.Parameter.ToString());
switch (message.Parameter.ToString())
{
case "BaseThreeExit": /*模拟防真结束*/
MySetTime.SetSysTime();
main.SimulaFinish();
Console.WriteLine("List remaint =" + FileControl.GetBaseStationNumber());
break;
}
}
}
//发送 消息
App 是主线程 类
App.QueMessages.PushMessage(this, "BaseThreeExit");
App.QueMessages.PushMessage(this, (object)MySetTimeTemp);
*/
- WPF 之消息队列
- UCOS之消息队列
- IPC之消息队列
- 数据结构之消息队列
- 事件之消息队列
- IPC之消息队列
- linux之消息队列
- 消息队列之ActiveMQ
- linuxIPC之消息队列
- IPC之消息队列
- IPC之消息队列
- 分布式之消息队列
- Wpf消息循环之消息传递
- 消息队列之JMS消息服务讲解
- 进程通信之消息队列
- 学习笔记之消息队列
- 进程通信之消息队列
- Linux通信之消息队列
- Android UI简单美化
- HDU1312 Red and Black 搜索入门
- 深入Java集合学习系列:HashMap的实现原理
- Linux编写Shell脚本自动同步svn并发布maven项目-Linux服务器用户设置
- 看源码学知识(不定期更新)
- WPF 之消息队列
- [leetcode][hash] Single Number II
- Android学习笔记--SharedPreferences的使用
- 51单片机项目 模拟智能传送装置
- 23.创建ViewController的三种方式
- java中 编码 解码 乱码 解惑
- Vijava学习笔记之(HostSystem 内存(总容量和已使用))
- 命令行中的数据科学
- Vjava学习笔记之(VirtualMachine 内存(总容量和已使用))