将参数传递给先前启动的程序实例
我需要编写将给出某个路径作为参数的程序,并播放位于该路径中的音频文件。但是在我第二次调用该程序之后 - 我需要第一个程序来完成播放文件,然后播放第二个文件,该文件作为参数传递给第二个实例。如果可能的话,如何将第二个参数作为队列传递给第一个程序实例?
I need to write program that will be given some path as a parameter, and play audiofile, located in that path. But after i call that program second time-i need first one to finish playing file and after that-play second file, that was passed as a parameter to second instance. How to pass second parameter as queue to first program instance if its possible..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜您正在描述以下策略:-
显然,这就是 VLC 媒体播放器的工作方式。如果您尝试上述操作,您将在当前实例开始播放新曲目之前看到一个新的 VLC 进程出现一小段时间。
这种非常简单的跨进程通信可以使用类似 系统 来实现.Threading.Mutex。例如,您可以使用一个互斥体来指示当前正在运行的实例的存在,并使用另一个互斥体来将新的轨道名称传递给当前实例。
事实上,这篇文章描述了非常相似的东西。
I guess you're describing the following strategy:-
Evidently this is the way VLC media player works. If you try the above, you will see a new VLC process appear for a short time before your current instance starts playing the new track.
This kind of very simple cross process communication can be achieved using something like System.Threading.Mutex. E.g. you could use one mutex to indicate the existence of a currently running instance and another for passing the new track name to the current instance.
In fact, this article describes something quite similar.
我认为您不需要为此目的使用第二个程序实例。您可以简单地要求第一个程序在播放完第一个音频文件后播放新的音频文件。您可以通过多种方式实现这一目标。
您可以在程序中托管一个 WCF 服务来播放音频文件。它将播放音频并并行监听 WCF 服务。发送第二个参数的程序将通过 WCF 服务传递新路径。
同样,您可以使用套接字进行通信
第三种方法可能是使用 Windows 消息队列。音频播放器将不断地为新路径汇集队列。第二个程序将通过在 Windows 消息队列中添加消息来发送新文件路径
您也可以使用文件进行通信。音频播放器可以查找文件中的更改,其他程序可以写入该文件的路径
I don't think you need second instance of program for this purpose. You can simply ask the first program to play the new audio file once it has finished playing the first. You can achieve this via several ways.
You can host a WCF Service inside your program which plays the audio file. It will be playing audio and will be listening to WCF Service in parallel. Program that sends the second parameter will pass the new path via WCF Service.
Similarly you can use sockets for communication
A third way could be to use Windows Message Queues. Audio player will be continuously pooling the queue for the new paths. The second program will send the new file path via adding a message in Windows Message Queue
You can also use files for communication. Audio player can look for changes in file and other program can write paths to that file