简体   繁体   English

让多个 .NET 应用程序相互通信的最佳方式

[英]Best way to let multiple .NET apps communicate with each other

So, first of all sorry for my bad english.所以,首先对不起我的英语不好。 Back to the questio, i have a main app, with a tab control, each tab contain another .NET exe.回到问题,我有一个主应用程序,带有一个选项卡控件,每个选项卡都包含另一个 .NET exe。 These need to send infos to the main app.这些需要将信息发送到主应用程序。 Example: Each exe in a tab have a random generated guid every second and the main app need to catch this and show in a listview or something as long the exe is "alive".示例:选项卡中的每个 exe每秒都有一个随机生成的 guid,主应用程序需要捕获它并在列表视图中显示或只要 exe 是“活动的”。

Currently i'm using SQLite, and everytime a new exe is started this one write in a table.目前我正在使用 SQLite,每次启动一个新的 exe 时,都会在表格中写入。 Before closing it this exe remove the recod from the table.在关闭它之前,这个 exe 从表中删除记录。 In the mainwhile, the main app retrieve this update table and show the "alive" exe and the random generated guid (every second).在主应用程序中,主应用程序检索此更新表并显示“活动”exe 和随机生成的 guid(每秒)。 All works fine, the problem is that i need to abandon this method and remove the two dll of SQLite.一切正常,问题是我需要放弃这种方法并删除 SQLite 的两个 dll。

What i tried is:我尝试的是:

  • UDP socket between the N clients and the main app, but is not so stable. N 个客户端和主应用程序之间的 UDP 套接字,但不是那么稳定。 And sometime some exe got freezed.有时一些exe被冻结。 (using TCP will be so "heavy" for the only purpose to send a short string. Right?) (使用 TCP 将如此“重”,仅用于发送短字符串。对吗?)
  • Changing the window text of the other exe and retrive it via processinfo, but is not updating it, i get it just the first time string.更改另一个exe的window文本并通过processinfo检索它,但没有更新它,我只是第一次得到它。

So, there is a way for that?那么,有没有办法呢? In local.在当地。 Like, i don't know.. user32 sendmessage maybe?就像,我不知道.. user32 sendmessage 也许? Or this method is too invasive for just a short string?或者这种方法对于短字符串来说太具有侵入性了? Considering that the N sub exe are process "inside" the main one, there is not a way to obtain infos from child process?考虑到 N 个子 exe 是主进程“内部”的进程,没有办法从子进程获取信息吗?

Thanks for your help!谢谢你的帮助!

UDP does not guarantee delivery of the packet by-desing. UDP 不保证按设计交付数据包。 Unless you implement your own confirmation protocol above it.除非你在它上面实现你自己的确认协议。 But implementation itself should be stable.但是实现本身应该是稳定的。

Using TCP will provide similar results.使用 TCP 将提供类似的结果。 You'll just have to deal with reconnect stuff.你只需要处理重新连接的东西。

SendMessage/PostMessage is the easiest and straight forward method. SendMessage/PostMessage 是最简单直接的方法。 But it will not allow you to pass string directly.但它不允许你直接传递字符串。 Take a look at RegisterWindowMessage to register your own message and SendMessage with HWND_BROADCAST handle.查看 RegisterWindowMessage 以注册您自己的消息并使用 HWND_BROADCAST 句柄注册 SendMessage。 And you'll have to send pointer to your string.而且您必须将指针发送到您的字符串。 Since SendMessage is synchronous you should be teoreticaly fine with disposing of that message, but I haven't tried that.由于 SendMessage 是同步的,因此您应该可以很好地处理该消息,但我还没有尝试过。 Another option would be storing string somewhere-else (registry, file) and sending just update notification using SendMessage.另一种选择是将字符串存储在其他地方(注册表、文件)并使用 SendMessage 发送更新通知。 And the main app will read and delete that registry/file record.主应用程序将读取并删除该注册表/文件记录。

Self hosted WCF with netNamedPipeBinding should work as well.带有 netNamedPipeBinding 的自托管 WCF 也应该可以工作。 But that would be propably too robust solution.但这可能是过于强大的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 同一台机器上的两个程序相互通信的最佳方法是什么 - What is the best way for two programs on the same machine to communicate with each other 将多个相互依赖的.NET Core程序包上传到NuGet的最佳方法? - Best way to upload multiple .NET Core packages with dependencies to each other to NuGet? 多个WCF服务可以相互通信吗? - Can multiple WCF services communicate with each other? 两个单独的 C# .Net 应用程序在同一台计算机上相互通信的最简单方法是什么 - What is the easiest way for two separate C# .Net apps to talk to each other on the same computer 合并多个Windows Phone应用的最佳方法 - Best way to merge multiple Windows Phone apps 通过 sockets 进行通信的最佳方式 - Best way to communicate through sockets 表格之间沟通的最佳方式? - Best way to communicate between forms? ASP.NET MVC应用程序与客户端(带有Windows Mobile的移动设备)进行通信的最佳方式 - Best way for an asp.net mvc application to communicate with client (mobile devices with windows mobile) 处理控件的最佳方法是自动更新对方? - Best way to handle controls automatically updating each other? 模型可以在MVVM中相互通信吗 - Can Models communicate with each other in MVVM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM