-
Mar 24th, 2010, 06:47 AM
#1
Thread Starter
New Member
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
-
Mar 24th, 2010, 06:54 AM
#2
Fanatic Member
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.
-
Mar 24th, 2010, 06:56 AM
#3
Lively Member
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
-
Mar 24th, 2010, 07:00 AM
#4
Fanatic Member
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.
-
Mar 24th, 2010, 07:21 AM
#5
Lively Member
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?
-
Mar 24th, 2010, 07:23 AM
#6
Fanatic Member
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.
-
Mar 24th, 2010, 07:37 AM
#7
Lively Member
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.
-
Mar 24th, 2010, 07:41 AM
#8
Fanatic Member
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.
-
Mar 24th, 2010, 07:46 AM
#9
Thread Starter
New Member
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
-
Mar 24th, 2010, 07:47 AM
#10
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|