Send data to WPF singleton application from other process

元气小坏坏 提交于 2019-12-10 22:21:24

问题


I have a WPF singleton application, wherein only one instance is running at any time, if user tries to launch another instance, we check if its already running then we kill this new process and bring to front the existing one.

Now, we have a requirement to open/access and send message (set of arguments) to this WPF application from another process which can be xls, word, or another standalone application. We also want to make sure that if the process is already running, that process should hear the message and respond.

Any idea how we can implement it in our WPF application

Thanks


回答1:


The probably most interoperable way on Windows is using the WM_COPYDATA windows message to transfer data between applications.

You can find an example here and another one for WPF right here.




回答2:


MSDN provides a pretty good article on the communication option in .NET.

I personally had this problem twice on 2 differents applications.

First time we used a TCP based connection. This is really efficient, but you need to code a lot to make it works. What we observe is that it is hard to define a standard of communication because developpers are not used to work with TCP connection (in my context at least).

Thus the second time we use a WCF based connection. Our singleton WPF application host the connection, and the other application connect to it when available. It was a better experience as manage host service is pretty natural for most developpers (used to work with web services). Another avantage is that you can reach you WPF singleton through a web connection in the end if required.

Hope it helps.



来源:https://stackoverflow.com/questions/25418768/send-data-to-wpf-singleton-application-from-other-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!