.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 实现通用消息处理窗口的更多相关文章

  1. Winform应用程序实现通用消息窗口

    记得我之前发表过一篇文章<Winform应用程序实现通用遮罩层>,是实现了透明遮罩的消息窗口,功能侧重点在动图显示+消息提醒,效果看上去比较的炫,而本篇我又来重新设计通用消息窗口,功能重点 ...

  2. 浅析 Android 的窗口

    来源:http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=555&fromuid=6   一.窗口的概念 在开发过程中,我们经常会 ...

  3. Unity3d UGUI 通用Confirm确认对话框实现(Inventory Pro学习总结)

    背景 曾几何时,在Winform中,使用MessageBox对话框是如此happy,后来还有人封装了可以选择各种图标和带隐藏详情的MessageBox,现在Unity3d UGui就没有了这样的好事情 ...

  4. Android中将布局文件/View添加至窗口过程分析 ---- 从setContentView()谈起

    本文主要内容是讲解一个视图View或者一个ViewGroup对象是如何添加至应用程序窗口中的.下文中提到的窗口可泛指我们能看到的界面,包括一个Activity呈现的界面(我们可以将之理解为应用程序窗口 ...

  5. 浅析Android的窗口

    一.窗口的概念 在开发过程中,我们经常会遇到,各种跟窗口相关的类,或者方法.但是,在 Android 的框架设计中,到底什么是窗口?窗口跟 Android Framework 中的 Window 类又 ...

  6. Winform应用程序实现通用遮罩层二

    之前先后发表过:<Winform应用程序实现通用遮罩层>.<Winform应用程序实现通用消息窗口>,这两款遮罩层其实都是基于弹出窗口的,今天为大家分享一个比较简单但界面相对友 ...

  7. 8-Flink中的窗口

    戳更多文章: 1-Flink入门 2-本地环境搭建&构建第一个Flink应用 3-DataSet API 4-DataSteam API 5-集群部署 6-分布式缓存 7-重启策略 8-Fli ...

  8. electron_window 创建窗口

    /** * 窗口基类,封装通用的窗口操作 */ const { BrowserWindow } = require('electron'); /** * 基本窗口样式 * @type {{width: ...

  9. Windoows窗口程序一

    编写窗口程序的步骤: .定义WinMain入口函数 .定义窗口处理函数(处理消息)WindowProc .注册窗口类RegisterClass .创建窗口(在内存中创建窗口)CreateWindow ...

随机推荐

  1. table新增空白行到首行

    var str=""; str+="<tr bordercolor='#DEDEDE' bgcolor='#ffffff'>"; str+=&quo ...

  2. Oracle where 0=1 or 1=1

    本文转载自:http://www.cnblogs.com/junyuz/archive/2011/03/10/1979646.html sql where 1=1和 0=1 的作用   where 1 ...

  3. mxml日期显示使用

    mxml代码: <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx= ...

  4. spice up your desktop

    https://wiki.gnome.org/Projects/GnomeShell/CheatSheet windows10用了一段时间,回来看着gnome3-shell是那么的恶心,翻来翻去重新整 ...

  5. 设置TabBar分栏控制器上图片的大小问题

    我们都知道,iOS因为屏幕分辨率的问题,UID在交付我们iOS开发人员程序配图的时候,一般是三套图,分别对应三种不同的分辨率,对不同size的屏幕系统会自动使用不同像素的图片,我们只需要在命名时给三套 ...

  6. js设置全局变量ajax中赋值

    js设置全局变量,在ajax中给予赋值赋值不上问题解决方案 方案一. //在全局或某个需要的函数内设置Ajax异步为false,也就是同步. $.ajaxSetup({async : false}); ...

  7. perfect-scrollbar示例

    <!DOCTYPE html> <html> <head> <title>perfect-scrollbar - www.97zzw.com -97站长 ...

  8. Swift POP+MVVM

    Swift2.0中引入了协议扩展的特性,并且建议开发者一切从协议(Protocol)出发,经过几个月的学习探索,博主发现Swift作为一门面向协议编程(POP)的语言非常适合时下火热的MVVM架构.M ...

  9. ubuntu中安装myeclipse提示Insufficient Memory解决方法

    经过查看资料发现出现这个问题的原因是因为计算机中swap分区的内存不足,或者没有创建swap分区,google中http://www.bkjia.com/webzh/1003601.html提供了一种 ...

  10. PullToRefreshGridView上拉加载、下拉刷新

    eclipse中的项目: //注意:此刷新功能是使用的第三方的PullToRefreshScrollView,因此需要导入第三方library作为依赖 步骤:导入第三方library,依赖:点击你的应 ...