本文介绍了我如何可以通过命令行参数到一个已经运行的进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个联系人管理程序。我知道如何读取命令行参数,并执行依据是什么,我觉得不同的方法。

I am writing a contact management program. I know how to read command-line arguments, and perform different methods based on what I find.

例如, PROGRAM.EXE李四将启动该程序的新实例,并打开了第一次接触它认定命名为李四, PROGRAM.EXE -s约翰将启动该程序的新实例,并搜索联系人名为约翰,而只需运行 PROGRAM.EXE 将打开启动该程序的新实例有一个空白的搜索屏幕。

For example, program.exe "John Doe" will start a new instance of the program and open up the first contact it finds named John Doe, program.exe -s John will start a new instance of the program and search for contacts named "John," whereas simply running program.exe will open start a new instance of the program with a blank search screen.

我想然而,仅运行该程序的一个实例,。所以,当其他程序调用 PROGRAM.EXE李四,如果已经有一个进程运行,该参数将被传递到过程,并切换到一个新的搜索,而不是打开一个新窗口。

I would like to only run a single instance of the program, however. So when another program calls program.exe "John Doe", if there is already a process running, the arguments will be passed to that process and switch to a new search rather than opening a new window.

我知道,这需要寻找previously正在运行的进程和进程间通讯,但我没有做太多的无论是在.Net和时遇到了正确的方向起步或找到的任何好的教程特定的主题。

I know that this requires looking for previously running processes and inter process communication, but I've not done much of either in .Net and am having trouble getting started in the right direction or finding any good tutorials on the specific subject.

推荐答案

<一个href="http://www.hanselman.com/blog/TheWeeklySource$c$c31SingleInstanceWinFormsAndMicrosoftVisualBasicdll.aspx" rel="nofollow">http://www.hanselman.com/blog/TheWeeklySource$c$c31SingleInstanceWinFormsAndMicrosoftVisualBasicdll.aspx

Visual Basic中的DLL有一个WindowsFormsApplicationBase有StartupNextInstance事件中,你可以得到二审和二审的参数可以杀死本身检测其他实例。

Visual basic dll has a WindowsFormsApplicationBase that has StartupNextInstance event in which you can get the arguments of the second instance and the second instance can kill itself on detecting other instances.

这个已被问C# :如何 - 接受新的参数,单实例应用程序

这篇关于我如何可以通过命令行参数到一个已经运行的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:30