0

I have a program that is running in the background, this program has to be notified when a specific windows event is occurring.

I know the name and id for the event and i know how to schedule an action for it in the task scheduler, but here i can only start a new program. I want to call a function in an already running application.

Edit: Solved it like this.

The main program is listening for a TCP connection and from the task scheduler i start another instance of the program with a command line argument. If the program receives this argument it will connect to the main program that performs some action when it receives the connection.

4

3 回答 3

1

我会让调度程序启动一个新进程(它可能是同一个应用程序 exe)并让这个进程设置一个第一个进程正在等待的事件。对我来说似乎很干净,特别是如果您让调度程序启动相同的应用程序(可能使用特殊的命令行)。

于 2009-03-14T19:59:51.563 回答
0

我不确定您所说的“Windows 事件”是什么意思——实在太多了!您在标题中谈论的是任务调度程序,但您在问题中所写的内容似乎表明您在调度程序的帮助下正在寻找一些外部更改。我假设它不是键盘、鼠标或 Windows 事件,因为这就是 GUI 框架的用途。

如果“胶水”应用程序方法对您来说不够优雅或不够快,我会说深入研究 Windows Management Instrumentation。查看MSDN上的这篇文章作为入门,也许这篇文章是关于如何在 VS 中工作的:如果失败,您可能必须下降到COM 互操作级别来注册您的侦听器。

您还没有说明您的“后台应用程序”是如何实现的:无论是作为有或没有窗口/GUI 的正常进程,还是作为 Windows 服务,或更现代的 . 我认为 WMI 侦听器可以处理所有这些,但思考不能替代测试(反之亦然!)。

我有些犹豫地提供了这个建议:WMI 基于DCOM,如果您开始跨网络工作,有时在单台机器上(在不同的用户帐户下运行)工作,这可能会给您带来痛苦。我敢肯定,在所有神秘的参数和配置之下,有一个经过深思熟虑的安全模型!

于 2009-03-15T10:24:28.240 回答
0

我支持(并赞成)默里的评论。只需启动一个新进程,该进程“通知”事件发生的现有进程然后终止。如果您只需要知道它发生在等待一个全局事件(windows 这个词的意思,而不是 .net 的)似乎很简单。

于 2009-03-14T20:07:23.620 回答