简体   繁体   English

在2个C#应用程序实例之间传递字符串

[英]Passing string between 2 C# application instances

I built a media player, that media player is associated with several media file types. 我建立了一个媒体播放器,该媒体播放器与几种媒体文件类型相关联。
Every time that a user opens a media file, I check if my player is open. 每次用户打开媒体文件时,我都会检查播放器是否打开。
I managed to prevent opening two instances but I want to pass the file path to the already opened instance. 我设法避免打开两个实例,但是我想将文件路径传递给已经打开的实例。

I am using mutex to prevent opening and I have been trying to use SendMessage to pass strings. 我正在使用互斥锁来防止打开,并且我一直在尝试使用SendMessage传递字符串。
What is the best way to do so? 最好的方法是什么?

I think a good way is to create a WCF service into your media player. 我认为一种好方法是在媒体播放器中创建WCF服务。 You will can communicate easily with it. 您将可以轻松地与之交流。 See the ServiceHost class 请参阅ServiceHost

Try named pipes , ie NamedPipeServerStream & NamedPipeClientStream . 尝试命名管道 ,即NamedPipeServerStreamNamedPipeClientStream Some general overview is avaibale here as well, although in your case basic write-to-temp-lock-file/read-from-temp-lock-file might not be such a bad idea. 这里也提供一些常规概述,尽管在您的情况下,基本的临时锁定文件写入/临时锁定文件读取可能不是一个坏主意。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM