仅调用一次 exe 的过程
我正在使用 process.info, process start();在 c#.net 中单击按钮调用 exe,但每次我单击按钮时,它都会调用 exe 并在任务栏上打开一个重复文件。我只想最大化任务栏上已有的 exe。
我面临的问题是,单击按钮时一次又一次打开同一个文件。 有什么方法可以只打开一个exe文件一次,然后单击按钮可以最大化exe文件(如果已经打开)而不是重复输入?
I'm using process.info, process start(); to call an exe on button click in c#.net, but every time I click on the button it calls an exe and opens a duplicate file on the taskbar. I want to just maximize the exe that was already on the taskbar.
I'm facing the problem that it is again and again opening the same file on the button click.
Is there any way that it could open an exe only once and on the button click it could maximize the exe file if already opened rather than making duplicate entries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Process.Start() 返回一个 Process 对象。您可以做的是拥有一个类变量(例如
ProcessstartedProcess;
),该变量在单击按钮时初始化。如果该变量为空,则意味着该进程尚未启动,该应用程序应该启动,否则它已经在运行,我们应该忽略它。下面是一个基本示例:
如果您希望在应用程序已经运行的情况下自动切换到该窗口,.NET 没有任何内置方法可以本机执行此操作。您将需要从 user32.dll 进行 DLLImports。可以在此页面的评论中找到示例: http://www.eggheadcafe.com/community/aspnet/14/21984/switch-to-another-runnin.aspx
Process.Start()
returns aProcess
object. What you could do is have a class variable (for exampleProcess startedProcess;
) that is initialized when the button is clicked. If that variable is null that means the process hasn't started yet, and that application should be launched, otherwise it's already running, and we should ignore it.Here is a basic example:
If you are looking to automatically switch to that window in the case that the application is already running, .NET does not have any built in methods to do this natively. You will need to to DLLImports from user32.dll. An example can be found in the comments on this page : http://www.eggheadcafe.com/community/aspnet/14/21984/switch-to-another-runnin.aspx
这应该会让你迈出正确的一步:
http://www.webdevbros.net/2007/11 /14/singelton-application-with-c/
this should get you off on the right foot:
http://www.webdevbros.net/2007/11/14/singelton-application-with-c/