zoukankan      html  css  js  c++  java
  • InterProcess Communication

    今天由于想找Firefox下的一个Google Docs插件,结果找到了GoogleDocListUploader,基于Google的Doc List API写的一个实例程序。这里有一篇讲解代码和设计的文章,虽然是个没有难度的工具,但作者的介绍非常细心。

    有三个地方给我留下了印象:

    1. 使用Mutex控制程序只有一个的实例;
      Mutex mutex = new Mutex(true, "Local\\DocListUploader", out firstInstance);
      //Local保证了操作系统切换到其它用户身份登录时,可以开启程序的新实例
    2. 利用注册表操作向Windows Shell中添加右键菜单项;
    3. Inter-Process Communication(进程间通信)
      这是以前自己做WinForms时的弱项,.NET 2.0提供了IPC机制,找时间学习一下。
      //主进程监听后续进程
      public void ListenForSuccessor()
      {
          IpcServerChannel serverChannel = new IpcServerChannel("DocListUploader");
          ChannelServices.RegisterChannel(serverChannel, false);

          RemoteMessage remoteMessage = new RemoteMessage(this);
          RemotingServices.Marshal(remoteMessage,"FirstInstance");
         
      }
      //后续进程通知主进程
      public static void NotifyPredecessor(string file)
      {
          IpcClientChannel clientChannel = new IpcClientChannel();
          ChannelServices.RegisterChannel(clientChannel, false);

          RemoteMessage message = (RemoteMessage) Activator.GetObject(typeof(RemoteMessage),
            "ipc://DocListUploader/FirstInstance");

          if (!message.Equals(null))
          {
              message.SendMessage(file);
          }
      }
    yicone
    -The future is worth fighting for.
  • 相关阅读:
    Lua中的closure、泛型for
    Lua多重继承
    (转)C++ new详解
    C++重载操作符学习
    Lua中使用继承来组装新的环境
    DOS:变量嵌套和命令嵌套
    C++中成员的私有性
    ManualResetEvent 类
    在IIS中部署和注册WCF服务
    ArcGIS Server 10 地图缓存新特性
  • 原文地址:https://www.cnblogs.com/yicone/p/1086443.html
Copyright © 2011-2022 走看看