打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Multi-process C# app like Google Chrome
January 5th, 2010

2 months ago we released wyBuild & wyUpdate v2.5. This release adds a free automatic updater control for C# & VB.NET apps. And because we wanted to keep things simple we left the wyUpdate.exe to do all the hard work (checking, download, installing) in the background while the AutomaticUpdater control is visible on your app’s main form.

We wanted the AutomaticUpdater to be able to control the update steps, view progress, and cancel the updating. But we also wanted to keep all the updating logic in the wyUpdate.exe. For this to be successful we needed a way for the AutomaticUpdater control to talk to wyUpdate.exe while it’s running.

The Answer: Inter-process communication (IPC)

Inter-Process communication is a fancy computer science way of saying “processes that can talk to each other”. Google Chrome uses IPC to communicate between tabs of the browser & plugins. It’s a simple way to keep parts of your program isolated from crashes.

For instance, if a tab of Google Chrome crashes only that single tab is killed. The rest of your tabs will continue to function normally.

Lots of bad ways to do IPC

Now that you know what inter-process communication is, let me tell you the worst ways to do it.

  • Shared memory: Difficult to set up & difficult to manage.
  • Shared files / registry: Very slow due to the writing & reading to/from disk. Difficult to manage.
  • SendMessage / PostMessage: Locks up the UI thread while the message is processed. Messages are limited to integer values. Can’t communicate from a non-admin process to an admin process. Assumes that your processes have a window.

Named Pipes

Inter process communication using named pipes is what Google Chrome uses and what we use for wyUpdate and the AutomaticUpdater control. Let me teach you about named pipes.

“Like Mario’s pipes?”

Exactly like Mario’s pipes. Except, instead of jumping Mario through the pipe, you push data through the pipe:

What do you put in the pipe?

You can transfer any data between your processes. So what data should your transfer? The answer is “it depends”. The rule of thumb is to keep it short, and keep it simple. Here’s what we do with the named pipe between wyUpdate and the AutomaticUpdater control sitting on your application:

  • Command codes: The AutomaticUpdater can command wyUpdate to check for updates, download the updates, extract the update, and install the update, or cancel any current progress.
  • Responses: wyUpdate can tell the AutomaticUpdater if there’s an update available, what changes there are in the update, and the progress of the current step (e.g. downloading).

With this simple setup the AutomaticUpdater control that’s on your application is completely isolated from wyUpdate.

Get the C# source

Download the named pipes C# source. It works with .NET 2.0, 3.0, 3.5 on Windows 2000 – Windows 7.

There are two files that do all the work: PipeServer.cs and PipeClient.cs. We use the PipeServer.cs file inside wyUpdate, and we use the PipeClient.cs file inside the AutomaticUpdater control.

Also included in the zip file is a simple messaging program to demonstrate communication between two separate processes:

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Google Chrome 未响应。是否立即重新启动?
selenium webdriver 环境搭建–java
CentOS7 安装 chrome
如何匯出、匯入 Google Chrome 裡面的全部帳號密碼?(按一下輕鬆備份) – 【重灌狂人】
Chrome强制http定向到https方法 | 乱炖
Google Chrome 4.1.249.1059 Released
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服