.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. js里写网页结构, 传函数参数

    如题 "<td align='center' height='30px' width='80px'><a href='javascript:sort(\"&quo ...

  2. 打不开BT,一直重复的关闭开启。

    /bt-btif (25335): ...preload_wait_timeout (retried:0/max-retry:1)...D/bt_userial(25335): RX terminat ...

  3. CentOS 安装及配置Salt api

    安装 # yum -y install salt-api 更改配置 vim /etc/salt/master 把默认的注释掉  我们这边默认配置文件目录是/srv/salt default_inclu ...

  4. table边框设置

    一.表格的常用属性基本属性有:width(宽度).height(高度).border(边框值).cellspacing(表格的内宽,即表格与tr之间的间隔). cellpadding(表格内元素的间隔 ...

  5. Bill Total Value

    Bill Total Value time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. json对象的简单介绍

    1.JSON(JavaScript Object Notation)一种简单的数据格式,比xml更轻巧.JSON是JavaScript原生格式,这意味着在JavaScript中处理JSON数据不需要任 ...

  7. servlet中路径的获取

    1.获取项目的绝对路径 可以request.getRealPath("/"),但是这个方法已经废弃了,最好用this.getServletContext().getRealPath ...

  8. KVO 进阶

    Key-value coding (KVC) 和 key-value observing (KVO) 是两种能让我们驾驭 Objective-C 动态特性并简化代码的机制.在这篇文章里,我们将接触一些 ...

  9. Gson解析数据

    package com.bwie.test;import java.io.BufferedReader;import java.io.IOException;import java.io.InputS ...

  10. 8--UI 初步认识 简易计算器

    UI是App的根基:一个App应该是先有UI界面,然后在UI的基础上增加实用功能(2)UI相对简单易学:UI普遍是学习过程中最简单的一块,能快速拥有成就感和学习兴趣(3)UI至关重要:开发中的绝大部分 ...