Results 1 to 10 of 10

Thread: multiple instance program

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Location
    Vermont
    Posts
    12

    multiple instance program

    I've tried searching this forum for an answer to my problem with no luck. I've set my program to allow multiple instances of it to run. Is it possible for each instance of it to determine if it was the first, 2nd, 3rd, etc to be opened? It would be very useful if for example if the program has been opened a 2nd time I would like to be able to load a different set of parameters for certain things for the 2nd instance. The same with the 3rd instance.

    Thanks.
    Pete

  2. #2
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: multiple instance program

    why not use multiple instances within the same app? you can control how the forms are named and act on this. doing what you initially suggest will involve using API to find the handles for all open instances. i guess these could be stored in a file in a directory all instances would look at (each instance gets its handle via an api and writes it to a file, when it is closing it removes this ref from the file) not an easy solution but if you like a challenge you could find it educational
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

  3. #3
    Lively Member zexor's Avatar
    Join Date
    Mar 2010
    Posts
    68

    Re: multiple instance program

    Could use Process.GetProcesses to get all the process running into an array. Then look at each process and see if any of them is your program and how many of them are running.

    Code:
            Dim count as integer = 0
            Dim myProcesses() As Process = Process.GetProcesses
            For Each myProcess As Process In myProcesses
                If myProcess.ProcessName = "your program" Then
                    count += 1
                End If
            Next

  4. #4
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: multiple instance program

    Zexor, that would only let the OP know how many instances were open (which could be done by looking in his taskbar) and not which one was a specific instance that needed a specific task
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

  5. #5
    Lively Member zexor's Avatar
    Join Date
    Mar 2010
    Posts
    68

    Re: multiple instance program

    he seems to only want the program to determine if its the 1st instance, or 2nd instance or 3rd instance opened then load a different set of parameters. So all you need is to count the processes already opened during load?

  6. #6
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: multiple instance program

    true enough, but how would each instance know this?
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

  7. #7
    Lively Member zexor's Avatar
    Join Date
    Mar 2010
    Posts
    68

    Re: multiple instance program

    well when the 1st instance load, there is no other process so it knows its no.1 And this only check during load so it wont change afterward. Same for the 2nd instance, it sees the first one is there and no other one, so it knows its no.2 and it load a different set of data. And so on.

  8. #8
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: multiple instance program

    good point. that would serve the purpose
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Location
    Vermont
    Posts
    12

    Re: multiple instance program

    Yes, I see how that would work. I was overthinking it initially. I was thinking that I would have to check the process starttime as well to determine which was older. Thanks for your help.

    Pete

  10. #10
    Lively Member zexor's Avatar
    Join Date
    Mar 2010
    Posts
    68

    Re: multiple instance program

    User32 api can also work, if you change the title everytime you use FindWindow to reflect if you are 1st 2nd or 3rd in the title.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width