仅调用一次 exe 的过程

发布于 2024-08-20 10:35:59 字数 206 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长发绾君心 2024-08-27 10:35:59

Process.Start() 返回一个 Process 对象。您可以做的是拥有一个类变量(例如 ProcessstartedProcess;),该变量在单击按钮时初始化。如果该变量为空,则意味着该进程尚未启动,该应用程序应该启动,否则它已经在运行,我们应该忽略它。

下面是一个基本示例:

Process startedProcess = null;

public void button1_Clicked(object sender, EventArgs e)
{

     if ( startedProcess == null )
          startedProcess = Process.Start("path\\to\\process.exe");

}

如果您希望在应用程序已经运行的情况下自动切换到该窗口,.NET 没有任何内置方法可以本机执行此操作。您将需要从 user32.dll 进行 DLLImports。可以在此页面的评论中找到示例: http://www.eggheadcafe.com/community/aspnet/14/21984/switch-to-another-runnin.aspx

Process.Start() returns a Process object. What you could do is have a class variable (for example Process 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:

Process startedProcess = null;

public void button1_Clicked(object sender, EventArgs e)
{

     if ( startedProcess == null )
          startedProcess = Process.Start("path\\to\\process.exe");

}

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文