Question

Locked

Single instance application question, VB.net - Solved

By Slayer_ ·
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

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

This question makes my head ache....recursive recursivity :)

by robo_dev In reply to Single instance applicati ...

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

Collapse -

Reponse To Answer

by Slayer_ In reply to This question makes my he ...

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.

Collapse -

Reponse To Answer

by Slayer_ In reply to This question makes my he ...

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

Collapse -

Reponse To Answer

by Slayer_ In reply to This question makes my he ...

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

Collapse -

Worked good, thanks

by Slayer_ In reply to Single instance applicati ...

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.

Back to Software Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums