<http://www.google.com/groups?selm=blgrft%24c51nq%244%40ID-208219.news.uni-berlin.de>
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
That is a good way to do it if you need to get a bit of information
about the previous proces - especially if your going to pass information
to it. But if you have simple needs, like all you care about is if it
is running - here is an alternate method.
Imports System.Threading
...
Sub Main()
Dim owned As Boolean
Dim mut As New Mutex(True, "myuniquemutexname", owned)
If owned Then
Application.Run(New MainForm())
mut.ReleaseMutex()
Else
MessageBox.Show("A previous instance is already running")
End If
End Sub
Anyway, it is an alternative that I use a lot :)
--
Tom Shelton
MVP [Visual Basic]
I remember I posted a link to a sample like this.
;-)
Michael Passalacqua
Portland Community College
CIS Faculty
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Crap! I hate when I don't scroll down! Sorry. I wasn't trying to take
away from your post Herfried... I was just trying to provide some
additional information (which I see was there, boy do I feel dumb :)
Here's another way: (watch out for word-wrap)
'This is the application's startup routine
'Check to see if a previous instance of this application is running already
If
(UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurren
tProcess.ProcessName)) > 0) Then
MessageBox.Show("Already running on your system.", AppDesc,
MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
--
------------------------------------------------------------------------
George Shubin Custom Software Development
dX Software Systems Database Applications
Ph: 503-981-6806 Fax: 503-982-0120
www.dxonline.com geo...@dxonline.com
------------------------------------------------------------------------
No problem. I am lazy too.
Notice that this will return a wrong result if there are more than one
processes running on the system which have the same process name but
belong to different applications.
Lazy, he calls him. What happened to forgetful, distracted, unobservant,
hasty?
I prefer hasty myself - as in keen to get back to post a solution ;-).
Actually there is a difference between your methods.
Dim FirstTimeIn As Boolean
Dim mut As New Mutex(True, "myuniquemutexname", FirstTimeIn)
If FirstTimeIn Then
versus
Dim mut As Mutex = New Mutex(False, "myuniquemutexname")
If mut.WaitOne(10, False) Then
Any advantages of one over the other?
Regards,
Fergus
What's the difference between an application name and a process name?
Regards,
Fergus
Let's say two developers write two different programms with the name
"Foo". If the user installs both of them (they are different!) into
different locations, for example
"C:\Program Files\Foo1\Foo.exe"
"C:\Program Files\Foo2\Foo.exe"
and then starts both of them, the process name of both application
instances (instances of _different_ applications) will be the same.
When shutting down all applications with the same name maybe instances
of other applications are killed too.
Thanks, that's what I believed, but I thought I might have missed
soimething.
I think it is unlikely in general to have the clash that you mention, but
I can see it happening with different versions of the same software or
utilities such as 'Calculator'.
Regards,
Fergus
To be honest, I don't really think so. I have never used the method
Herfried showed - I've always just used the constructor to determine if
I have recieved ownership... But, it looks like 6's to me.
Thanks. I prefer the first version - it looks less like technobabble -
especially with the renamed ownership variable.
Regards,
Fergus
That's exaclty what I wanted to say...
;-)
Are you related to the Herfried who I've been mud-wrestling with over in
the other threads?
You seem like such a nice chap!! ;-)
Regards,
Fergus
Are you the Fergus I wanted to plonk? Maybe there are two different
"Fergus Cooney" posting to this group.