将消息从一个正在运行的控制台应用程序发送到另一个

发布于 2024-07-12 22:24:48 字数 435 浏览 7 评论 0原文

我有一个控制台应用程序正在与 ftp 服务器进行一些长时间的同步。
另一个控制台应用程序准备一个本地文件系统,其中包含一些需要的更新文件。
然后,第二个目录将等待第一个目录完成,然后再交换最终目录名称,以便它在网络上可见。

我搜索了使同步应用程序与第二个应用程序通信它已完成工作的最佳方法。 它看起来像使用IPC数据复制 是最适合的解决方案。

问题有两个:

  • 我是对的吗? 有没有更直接的方法来达到相同的结果?
  • 有没有一种托管(.net)方法可以做到这一点?

I have one console app that is doing some lengthy syncing to an ftp server.
Another console app prepares a local filesystem with some needed updated files.
Then the second one will wait for the first one to finish before swapping a final directory name so it becomes visible on the web.

I searched for the best way to make the syncing app to communicate to the second app that it's finished it's job. It looks like Using Data Copy for IPC is the best suited solution for this.

Question is two fold:

  • Am I right? Is there a more straight forward way to get to the same result?
  • Is there a managed (.net) way to do this?

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

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

发布评论

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

评论(2

月亮坠入山谷 2024-07-19 22:24:48

如果您需要的只是通知一个应用程序另一个应用程序已完成其任务,那么最简单的方法是使用命名的 EventWaitHandle。 该对象是在无信号状态下创建的。 第一个应用程序等待句柄,第二个应用程序在完成工作后向句柄发出信号。 例如:

// First application
EventWaitHandle waitForSignal = new EventWaitHandle(false, EventResetMode.ManualReset, "MyWaitHandle");

// Here, the first application does whatever initialization it can.
// Then it waits for the handle to be signaled:
// The program will block until somebody signals the handle.
waitForSignal.WaitOne();

设置第一个程序等待同步。 第二个应用程序同样简单:

// Second app
EventWaitHandle doneWithInit = new EventWaitHandle(false, EventResetMode.ManualReset, "MyWaitHandle");

// Here, the second application initializes what it needs to.
// When it's done, it signals the wait handle:
doneWithInit.Set();

当第二个应用程序调用 Set 时,它会发出事件信号,第一个应用程序将继续。

If all you need is to notify one application that the other has completed its task, the easiest way would be to use a named EventWaitHandle. The object is created in its unsignaled state. The first app waits on the handle, and the second app signals the handle when it's finished doing its job. For example:

// First application
EventWaitHandle waitForSignal = new EventWaitHandle(false, EventResetMode.ManualReset, "MyWaitHandle");

// Here, the first application does whatever initialization it can.
// Then it waits for the handle to be signaled:
// The program will block until somebody signals the handle.
waitForSignal.WaitOne();

That sets up the first program to wait for synchronization. The second application is equally simple:

// Second app
EventWaitHandle doneWithInit = new EventWaitHandle(false, EventResetMode.ManualReset, "MyWaitHandle");

// Here, the second application initializes what it needs to.
// When it's done, it signals the wait handle:
doneWithInit.Set();

When the second application calls Set, it signals the event and the first application will continue.

简单气质女生网名 2024-07-19 22:24:48

IPC 的其他流行选项包括:

  • 命名管道远程
  • 处理 (.NET)
  • WCF

如果您只需要同步,则可以考虑 SemaphoreMutex 对象。 .NET 的 System.Threading 命名空间中存在一些类,如果您创建这些类的命名版本,那么它们将应用于整个计算机。

Other popular options for IPC include:

  • Named Pipes
  • Remoting (.NET)
  • WCF

If you only need synchronization, you may consider a Semaphore, or Mutex object. There are classes which exist in the System.Threading namespace for .NET If you create named versions of these, then they apply to the whole machine.

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