gpt4 book ai didi

c# - 彻底关闭通过另一个应用程序启动的应用程序的最佳方法

转载 作者:行者123 更新时间:2023-11-30 22:46:04 24 4
gpt4 key购买 nike

我找不到任何接近的答案,所以我正在咨询 SO 用户的经验:

场景:

我有两个小型 C# winforms 应用程序,其中一个充当服务器或主机,另一个充当客户端。他们通过 SQL Server 在配置设置方面共享数据。

我目前正在通过 Process.Start() 从服务器应用程序启动客户端应用程序(只需要定期运行)并通过 Process.CloseMainWindow() 终止它>(在进程列表中找到后)。

虽然看起来很干净,但我想知道是否有更好的方法。

问题:

哪种方式最好指示客户端应用程序关闭:

  • 继续使用 Process.CloseMainWindow()?
  • 在应用程序之间实现 WCF? (我需要有关如何执行此操作的帮助。)
  • 在 SQL 中设置一个客户端应用程序检查的变量?
  • 其他方式?

最佳答案

鉴于Process.Start(string)

A new Process component that is associated with the process resource, or null, if no process resource is started (for example, if an existing process is reused).

Process myProcess = Process.Start("client.exe");

然后您可以使用此值调用 CloseMainWindow:

myProcess.CloseMainWindow();

唯一不返回 Process 组件的重载是 parameterless method .

(顺便说一句,在我发布这个答案之前我没有阅读关于这个问题的评论)

关于c# - 彻底关闭通过另一个应用程序启动的应用程序的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2830582/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com