Question Locked

Single instance application question, VB.net - Solved

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am working on a program that distributes source code.

It is only supposed to allow one instance, every subsequent instance is supposed to pass its command line to the first instance.

This part works (mostly)

The problem I encounter, is if you select several files in Windows, and choose to open them in the program, both detect each other as a previous instance and it fails.

What can I do to prevent this? I am currently using this as my code to detect a previous instance.

If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
Return True
Else
Return False
End If

6 replies

by robo_dev

First guess is that the issue is that the file suffix is not returned by the GetProcessesByName function, therefore the function is not evaluating the current state as expected

http://bytes.com/topic/visual-basic-net/answers/379881-process-getprocessesbyname-does-not-work-expected

the other issue is simply timing....it's 'missing the turn' from a program execution standpoint.

http://www.vb-helper.com/howto_net_one_instance.html

by slayer_

It does catch it if the first instance is already running, but if they are launched at the same time, they catch each other.

I tried using a file to separate them, but then I get the opposite problem, sometimes the file doesn't exist in time for the second instance.

by slayer_

Whats odd is, app.previnstance worked perfect in VB6 on the same computers.

by slayer_

Your second link looks promising, I will give it a try, thanks

by slayer_

Now I have a new problem...

When selecting multiple folders, I frequently get windows saying it the program has stopped responding. But you can do it again on the same folders and it might work.
I got a feeling its the directoryinfo.getfiles("*") I am doing. I don't know a way around this.

This discussion is closed to new replies.