如何关闭(而不是杀死)另一个没有可见窗口的应用程序? (C#)

发布于 2024-09-24 14:12:45 字数 210 浏览 0 评论 0原文

我有一个安装程序,我想确保我的应用程序当前没有运行。如果是,我想关闭它(而不是杀死它,因为应用程序必须在退出时保存一些数据)。另一个问题是我的应用程序的窗口是隐藏的(而是显示托盘图标),因此 Process.MainWindowHandle 始终为 0。

我可以做什么来指示我的应用程序关闭?我可以直接向应用程序(而不是窗口)发送消息吗?

我们将非常感谢您的帮助。 格雷戈尔

I have an installation program in which I would like to make sure my application is not currently running. If it is, I would like to close it (not kill it, since the app has to save some data on exit). The additional problem is that the window of my application is hidden (the tray icon is shown instead), so Process.MainWindowHandle is always 0.

What can I do to signal my application to close? Can I send a message directly to the Application (not the window)?

Your help will be greatly appreciated.
Gregor

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

巷子口的你 2024-10-01 14:12:45

只是为了添加一些其他内容:命名管道

Just to throw something else into the mix: named pipes.

酒与心事 2024-10-01 14:12:45

您可以让 APP1 侦听特定端口,并在您希望应用程序正常关闭时向该端口发送消息。因此 APP2 必须了解 APP1 端口以及它期望的消息参数。

您还可以拥有某种消息队列(Windows 有它,或者您可能想要使用 SQL Service Broker 之类的东西)实现,并让一个应用程序将消息发送到队列,而另一个应用程序从队列读取消息

您也可以检查一下:< a href="http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library /ms644950(VS.85).aspx

You can probably have APP1 listen to a specific port and send a message to that port when you want the App to gracefully close. So APP2 has to be aware of APP1 ports and what message parameters it's expecting.

You can also have some sort of Message Queue (Windows has it or you might want to use something like SQL Service Broker) implementation and have one APP sending messages to the Queue and the other reading from the Queue

You might also check this out: http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx

治碍 2024-10-01 14:12:45

您可能可以使用 WINAPI 按类或窗口文本查找窗口句柄(即使它是隐藏的)。然后向应用程序发送一条 Windows 消息以将其关闭。

http://support.microsoft.com/kb/178893

You could probably use WINAPI to find the window handle (even if it is hidden) by class or window text. Then send a windows message to the application to close it.

http://support.microsoft.com/kb/178893

你穿错了嫁妆 2024-10-01 14:12:45

您可以使用 PostThreadMessage WinAPI 函数(通过 PInvoke) 。

You can use PostThreadMessage WinAPI function (via PInvoke).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文