问题描述
我正在创建一个使用 NZB 文件下载二进制文件的 (C#) 程序,我的应用程序在任何时候都可能只有一个实例在运行.
I'm creating a (C#) program that downloads binaries using NZB files, there may only be one instance of my application running at any time.
因此,当用户双击 .nzb 文件并且我的程序没有运行时,它应该启动并处理它(简单,文件注册).现在,如果我的程序已经在运行,我不想启动第二个实例 - 我希望已经运行的实例获取指定的文件.
So when a user doubleclicks an .nzb-file and my program is not running, it should start and process it (easy, file registration).Now if my program is already running, I do NOT want to launch a second instance - I want the already-running instance to pick up the specified file.
可以使用带有 .IsSingleInstance 技巧的 Visual Basic DLL 使我的应用程序成为单实例,但我不想去那里.
Making my app single-instance can be done using the Visual Basic DLL with the .IsSingleInstance trick, but I don't want to go there.
正确的方法似乎是使用互斥锁来确保我的应用程序是单实例的,但现在我被困在如何将指定的参数(.nzb 文件)传递给已经运行的实例.
The right way seems to be to use a mutex to ensure my app is single-instance,but now I'm stuck on how to pass the specified parameter (the .nzb file) to the already-running instance.
帮助将不胜感激!:-)
Help would be appreciated ! :-)
推荐答案
试试这个:你的主程序创建一个命名管道或其他进程间通信设施并监听它.您创建了一个单独的小程序,当以 NZB 文件作为参数运行时,它会打开管道,将文件信息输入其中,然后退出.然后,您的主程序会处理新文件并下载它.
Try this: Your main program creates a named pipe or other interprocess communication facility and listens on it. You create a separate small program that, when run with an NZB file as a parameter, opens the pipe, feeds the file info into it, and exits. Your main program then processes the new file and downloads it.
这篇关于C#:如何 - 接受新参数的单实例应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!