听在另一个应用程序事件 [英] Listen for events in another application

查看:140
本文介绍了听在另一个应用程序事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假如我有C#编写的两个应用程序。首先是第三方应用程序,引发了一个称为OnEmailSent。

事件

第二个是我写的,我想以某种方式订阅OnEmailSent即使是首次应用的自定义应用程序。

有什么办法,我可以在第二个应用程序以某种方式连接到第一个应用程序侦听OnEmailSent事件?

的实例

因此​​,对于进一步澄清,我的具体情况是,我们已经写在抛出一个OnEmailSent事件C#定制的第三方应用程序。我们可以看到该事件存在使用反射器。

我们想要做的是什么时候有这个组件发送电子邮件一些其他的动作发生。

我们能想到的最有效的方法是能够使用某种形式的IPC作为安德斯曾建议,并听取了OnEmailSent事件正由第三方组件提升。

由于该组件是用C#我们正在写另一C#应用程序,它可以将自身到执行的过程,当它检测到OnEmailSent事件已经提高它会执行它自己的事件处理code的想法玩弄


我可能失去了一些东西,但是从我了解的远程工作原理是,将需要界定某种契约的客户端可以订阅服务器。

我更想如果有人写,如Outlook,例如独立的应用程序的场景中,一个公开,我想从另一个应用程序订阅事件。

我想我想的场景是.NET调试器以及它如何可以连接到执行组件来检查code,而它的运行。


解决方案

为了让两个应用程序(独立进程)来交换事件,必须同意这些事件是如何沟通。有该方法许多不同的方式这样做的,并准确地使用可能取决于体系结构和环境。对于这种进程之间的信息交换的总称,是进程间通信(IPC)。存在这样做的IPC,最常见的是文件,管道,(网络)套接字,远程过程调用(RPC)和共享内存。在Windows上它也是通常使用窗口消息

我不知道这是如何工作在Windows .NET / C#应用程序,但在本地的Win32应用程序,你可以的消息>到外部进程的消息循环和挂钩。如果程序产生时所希望的功能被称为消息事件,这可能是一种方法来检测它。

如果你是自己实现这两个应用程序,您可以选择使用任何方法IPC你preFER。网络插座和更高级别的基于套接字的协议,如HTTP,XML-RPC和SOAP是很受追捧,因为它们允许你运行在不同的物理机器上的应用,以及(因为他们是通过网络连接)。

Suppose I have two applications written in C#. The first is a third party application that raises an event called "OnEmailSent".

The second is a custom app that I've written that I would like to somehow subscribe to the "OnEmailSent" even of the first application.

Is there any way that I could somehow attach the second application to an instance of the first application to listen for "OnEmailSent" event?


So for further clarification, my specific scenario is that we have a custom third party application written in c# that raises an "OnEmailSent" event. We can see the event exists using reflector.

What we want to do is have some other actions take place when this component sends an email.

The most efficient way we can think of would be to be able to use some form of IPC as anders has suggested and listen for the OnEmailSent event being raised by the third party component.

Because the component is written in C# we are toying with the idea of writing another C# application that can attach itself to the executing process and when it detect the OnEmailSent event has been raise it will execute it's own event handling code.


I might be missing something, but from what I understand of how remoting works is that there would need to be a server defining some sort of contract that the client can subscribe to.

I was more thinking about a scenario where someone has written a standalone application like outlook for example, that exposes events that I would like to subscribe to from another application.

I guess the scenario I'm thinking of is the .net debugger and how it can attach to executing assemblies to inspect the code whilst it's running.

解决方案

In order for two applications (separate processes) to exchange events, they must agree on how these events are communicated. There are many different ways of doing this, and exactly which method to use may depend on architecture and context. The general term for this kind of information exchange between processes is Inter-process Communication (IPC). There exists many standard ways of doing IPC, the most common being files, pipes, (network) sockets, remote procedure calls (RPC) and shared memory. On Windows it's also common to use window messages.

I am not sure how this works for .NET/C# applications on Windows, but in native Win32 applications you can hook on to the message loop of external processes and "spy" on the messages they are sending. If your program generates a message event when the desired function is called, this could be a way to detect it.

If you are implementing both applications yourself you can chose to use any IPC method you prefer. Network sockets and higher-level socket-based protocols like HTTP, XML-RPC and SOAP are very popular these days, as they allow you do run the applications on different physical machines as well (given that they are connected via a network).

这篇关于听在另一个应用程序事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆