Start an App once each PC

Z

Zorro

Hi all,

I've got a little problem with my current App.



This app should only start once on each computer.



Currently I make this in following way:

static void Main()

{

int Count = 0;

foreach(System.Diagnostics.Process pro in
System.Diagnostics.Process.GetProcesses())

{

if(pro.ProcessName == "AppName" && Count >= 1)

return;

else if(pro.ProcessName == "AppName ")

Count = 1;

}



Application.Run(new Form1 ());

}



This is very easy.



But now should there two changing's.



1.. When the Application will start again, the running app should be the
active windows
2.. When the Application will start again with arguments, the current app
should be the active window and an Event should fire (Open Form2).


I hope somebody have an idea, how I can implement this changing's.



Thanks,

Z
 
G

Guest

Zorro said:
1.. When the Application will start again, the running app should be the
active windows
2.. When the Application will start again with arguments, the current app
should be the active window and an Event should fire (Open Form2).

If you are interested in using a third-party component to solve your
problem, we offer a .NET component that's FREE for non-commercial use. When
another instance of your application starts, it will pass any arguments to
the original instance and then shut down. Check it out at:

http://www.mini-tools.com/goto/comm
 
J

Jim Wooley

But now should there two changing's.
1.. When the Application will start again, the running app should be
the
active windows
2.. When the Application will start again with arguments, the
current app
should be the active window and an Event should fire (Open Form2).
I hope somebody have an idea, how I can implement this changing's.

If you are using 2005, this is relatively easy. Under the project settings,
check the Enable Application Framework option and then check the Make Single
Instance Application option. To handle the additional command line arguments,
add a handler for the StartupNextInstance application event. You can grab
the command line arguments from the input parameters.

If you are using .Net 1.x, this is a bit more tricky. See my article on Single
Instance Winforms at http://devauthority.com/blogs/jwooley/archive/2005/07/28/318.aspx.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top