Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

running only one form

LordYTLordYT Member Posts: 16
How can I limit the user to run only one form a the time ?
Thanks

Comments

  • programmer07programmer07 Member Posts: 6
    I think I understand, but just to be certain...do you only want to allow the user to run once instance of your application? If so, do the following:

    Right-click your application in Solution Explorer. You'll see an option (Checkbox) to Make a Single Instance Application. That should do it.
  • LordYTLordYT Member Posts: 16
    Hi programmer07, thanks for the tip, I think you understand my problem good. But I'm working with vs2005 and I can't find the button you talk about. I'll keep looking for it. Thanks a lot.
  • aspongeasponge Member Posts: 42
    : Hi programmer07, thanks for the tip, I think you understand my
    : problem good. But I'm working with vs2005 and I can't find the
    : button you talk about. I'll keep looking for it. Thanks a lot.

    This is an old post, but in case anyone is wondering this should go in the Program.cs Main() method. This works when running the application on a local workstation and via terminal services.
    [code]
    using System.Diagnostics;
    Process proc = Process.GetCurrentProcess();
    string name = proc.ProcessName;
    int count = 0;
    foreach(Process p in Process.GetProcessesByName(name))
    {
    if(p.SessionId == p.SessionId)
    count++;
    }

    if(count < 1)
    {
    //start application
    Application.run(new MainForm());
    }
    [/code]
Sign In or Register to comment.