문제

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?

도움이 되었습니까?

해결책

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

다른 팁

this should get you off on the right foot: http://www.webdevbros.net/2007/11/14/singelton-application-with-c/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top