C# : how to - single instance application that acc

2019-01-08 23:36发布

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.

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.

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.

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 ! :-)

5条回答
Lonely孤独者°
2楼-- · 2019-01-08 23:53

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.

查看更多
姐就是有狂的资本
3楼-- · 2019-01-09 00:08

Using the "nice implementation", I had to add a writer.Flush() after the WriteLine() to have it working. I wasted a little time to find this...

查看更多
Juvenile、少年°
4楼-- · 2019-01-09 00:15

Use an IPC (inter process communication) mechanism such as .net remoting

查看更多
家丑人穷心不美
5楼-- · 2019-01-09 00:16

Why not have one program that adds the file to a queue, and then kicks off the downloading program if it is not already running. That downloading program watches the queue, which is just a file that you append download file names to.

查看更多
我想做一个坏孩纸
6楼-- · 2019-01-09 00:16

Look at the InitialInstanceActivator at the Genghis project

查看更多
登录 后发表回答