.net remoting 实现通用消息处理窗口
.net remoting 实现通用消息处理窗口
- 实现机制是制作一个cmd窗口作为信息展示窗口,主程序将需要展示的信息抛出到cmd窗口显示,以此方式做到消息的展示。
以下是cmd窗口的代码,cmd窗体作为一个消息接收的server
static void Main(string[] args)
{
try
{
//声明一个TCP通道指定端口8085
TcpChannel channel = new TcpChannel();
//注册通道
ChannelServices.RegisterChannel(channel, false);
//从哪个类,发出消息
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ToolFunction.ConsoleMessage), "ConsoleMessage", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Server:Press Enter key to exit");
//等待输入
System.Console.ReadLine();
}
catch (Exception)
{
throw;
} }
- 初始化client
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting; namespace ToolFunction
{
public class RemoteMessage
{
public static IMessage obj = null; /// <summary>
/// 初始化客户端
/// </summary>
public static void InitClient()
{
if (obj == null)
{
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel, false);
IMessage _obj = (IMessage)Activator.GetObject(typeof(IMessage), "tcp://localhost:8085/ConsoleMessage");
obj = _obj;
}
} /// <summary>
/// 发送消息
/// </summary>
/// <param name="p_strMess"></param>
public static void SendMessage(string p_strMess)
{
try
{
if (obj == null)
{
Console.WriteLine("Could not locate TCP server");
}
obj.ShowMess(p_strMess);
}
catch (Exception ex)
{
CommonFunction.WriteError(ex.ToString());
}
}
}
}
- 此类要实现一个接口MarshalByRefObject只有实现此接口才能实现remoting操作
using System;
using System.Collections.Generic;
using System.Text; namespace ToolFunction
{
public interface IMessage
{
void ShowMess(string p_strMess);
}
public class ConsoleMessage : MarshalByRefObject, IMessage
{
#region IMessage 成员 public void ShowMess(string p_strMess)
{
Console.WriteLine(p_strMess);
} #endregion
}
}
- 调用示例
//打开cmd程序
string _strExePath = Application.StartupPath + @"\MessagePlatform.exe";
Process.Start(_strExePath);
RemoteMessage.InitClient();
- 发送消息
RemoteMessage.SendMessage("测试消息" );
- 最后 的样子是这样的

.net remoting 实现通用消息处理窗口的更多相关文章
- Winform应用程序实现通用消息窗口
记得我之前发表过一篇文章<Winform应用程序实现通用遮罩层>,是实现了透明遮罩的消息窗口,功能侧重点在动图显示+消息提醒,效果看上去比较的炫,而本篇我又来重新设计通用消息窗口,功能重点 ...
- 浅析 Android 的窗口
来源:http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=555&fromuid=6 一.窗口的概念 在开发过程中,我们经常会 ...
- Unity3d UGUI 通用Confirm确认对话框实现(Inventory Pro学习总结)
背景 曾几何时,在Winform中,使用MessageBox对话框是如此happy,后来还有人封装了可以选择各种图标和带隐藏详情的MessageBox,现在Unity3d UGui就没有了这样的好事情 ...
- Android中将布局文件/View添加至窗口过程分析 ---- 从setContentView()谈起
本文主要内容是讲解一个视图View或者一个ViewGroup对象是如何添加至应用程序窗口中的.下文中提到的窗口可泛指我们能看到的界面,包括一个Activity呈现的界面(我们可以将之理解为应用程序窗口 ...
- 浅析Android的窗口
一.窗口的概念 在开发过程中,我们经常会遇到,各种跟窗口相关的类,或者方法.但是,在 Android 的框架设计中,到底什么是窗口?窗口跟 Android Framework 中的 Window 类又 ...
- Winform应用程序实现通用遮罩层二
之前先后发表过:<Winform应用程序实现通用遮罩层>.<Winform应用程序实现通用消息窗口>,这两款遮罩层其实都是基于弹出窗口的,今天为大家分享一个比较简单但界面相对友 ...
- 8-Flink中的窗口
戳更多文章: 1-Flink入门 2-本地环境搭建&构建第一个Flink应用 3-DataSet API 4-DataSteam API 5-集群部署 6-分布式缓存 7-重启策略 8-Fli ...
- electron_window 创建窗口
/** * 窗口基类,封装通用的窗口操作 */ const { BrowserWindow } = require('electron'); /** * 基本窗口样式 * @type {{width: ...
- Windoows窗口程序一
编写窗口程序的步骤: .定义WinMain入口函数 .定义窗口处理函数(处理消息)WindowProc .注册窗口类RegisterClass .创建窗口(在内存中创建窗口)CreateWindow ...
随机推荐
- 改变vim配色:安装colorscheme【转】
主要有两种方式安装colorscheme: 自行下载colorscheme安装,下载的文件扩展名通常为.vim. 通过安装相关vim的插件获取. 自行下载colorscheme安装 以mac为例,在系 ...
- oracle的exp和imp命令的使用【转载】
oracle的exp和imp命令的使用 我们通常要对ORACLE的数据进行导入,导出,在没有expdb,impdb以前(10G以前),我们都是使用exp 导出,imp命令来实现导入. 打开 ...
- perl的USE和require
来源: http://www.cnblogs.com/itech/archive/2010/11/22/1884345.html 相同: 都可以用来引用module(.PM). 不同: 1) 区别在于 ...
- List<T> 求差集
List<, , , , , }; List<, , , , , }; List<int> c = b.Except(a).ToList(); foreach (int i i ...
- mongodb分片
在系统早期,数据量还小的时候不会引起太大的问题,但是随着数据量持续增多,后续迟早会出现一台机器硬件瓶颈问题的.而mongodb主打的就是海量数据架构,他不能解决海量数据怎么行!不行!“分片”就用这个来 ...
- offset,client,scroll,style相关笔记
1.offsetTop 功能:获取元素上外缘与最近的定位父元素内壁的距离,如果没有定位父元素,则是与文档上内壁的距离 使用方法:js document.querySelector(...).offse ...
- Android Matrix类以及ColorMatri
引自:http://www.chinabaike.com/t/37396/2014/0624/2556217.html Android Matrix类以及ColorMatrix类详解 最近在系统学习了 ...
- html 7.28
1.HTML标记在没有添加任何样式的时候,默认是有间距的,所以我们要先把把所有标记归置内(padding)外(margin)边距归置为0 2.HTML5 中不支持 <acronym> 标签 ...
- SDAU课程练习--problemQ(1016)
题目描述 FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'med ...
- Linux学习 -- 日志管理
日志服务 rsyslogd CentOS6 取代了原来的syslog rsyslogd 默认启动.自启动 常用命令:lastb.lastlog.last.w.who.users. 系统默认日志 和 ...