473,503 Members | 11,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

its my app running??

some one knows how to check if my app. (Example ap1.exe)
is running (because i don't want than it run twice at the
same time in the same machine)

somebody knows like verifying if my application at the
moment this executing itself, since I do not want that
the application runs twice in the same computer at the
same time
Nov 20 '05 #1
6 1669
On 2003-11-06, Alex G. <ag******@ga.com.mx> wrote:
some one knows how to check if my app. (Example ap1.exe)
is running (because i don't want than it run twice at the
same time in the same machine)

somebody knows like verifying if my application at the
moment this executing itself, since I do not want that
the application runs twice in the same computer at the
same time


Start your application from a Sub Main, then you can do something like
the following:

Option Strict On
Option Explicit On

Imports System.Threading

....

Public Sub Main()
Dim firstInstance As Boolean
Dim mut As New Mutex(True, "myuniquemutexname", firstInstance)

If firstInstance Then
Try
' start your main form
Application.Run(New MainForm())
Catch
' Handle problems
Finally
' make sure the mutext is released
mut.ReleaseMutex()
End Try
Else
MessageBox.Show("App already running")
End If
End If

Just make sure that "myuniquemutexname" is unique and known to your
program. A mutex is a global kernel object, and so can be referenced by
all applications by using the unique name. If your application is given
ownership of the mutex, then firstInstance will be true - otherwise,
your app is already running :)

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #2
Nice, just asking myself about this :)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Tom Shelton" <to*@mtogden.com> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
On 2003-11-06, Alex G. <ag******@ga.com.mx> wrote:
some one knows how to check if my app. (Example ap1.exe)
is running (because i don't want than it run twice at the
same time in the same machine)

somebody knows like verifying if my application at the
moment this executing itself, since I do not want that
the application runs twice in the same computer at the
same time


Start your application from a Sub Main, then you can do something like
the following:

Option Strict On
Option Explicit On

Imports System.Threading

...

Public Sub Main()
Dim firstInstance As Boolean
Dim mut As New Mutex(True, "myuniquemutexname", firstInstance)

If firstInstance Then
Try
' start your main form
Application.Run(New MainForm())
Catch
' Handle problems
Finally
' make sure the mutext is released
mut.ReleaseMutex()
End Try
Else
MessageBox.Show("App already running")
End If
End If

Just make sure that "myuniquemutexname" is unique and known to your
program. A mutex is a global kernel object, and so can be referenced by
all applications by using the unique name. If your application is given
ownership of the mutex, then firstInstance will be true - otherwise,
your app is already running :)

--
Tom Shelton
MVP [Visual Basic]

Nov 20 '05 #3
Tom,

Is using the Mutex a more efficient or better way than doing it like this?

I place the following code in the Public Sub New() of the form code

Try
Dim StrProcessName As String
StrProcessName = Diagnostics.Process.GetCurrentProcess.ProcessName
If Diagnostics.Process.GetProcessesByName(StrProcessN ame).Length > 1 Then
'More than one instance was found
AppActivate(StrProcessName)
End
End If
Catch
'do nothing
End Try
thank you!

Shawn Shelton
Tom Shelton wrote:
On 2003-11-06, Alex G. <ag******@ga.com.mx> wrote:
some one knows how to check if my app. (Example ap1.exe)
is running (because i don't want than it run twice at the
same time in the same machine)

somebody knows like verifying if my application at the
moment this executing itself, since I do not want that
the application runs twice in the same computer at the
same time

Start your application from a Sub Main, then you can do something like
the following:

Option Strict On
Option Explicit On

Imports System.Threading

...

Public Sub Main()
Dim firstInstance As Boolean
Dim mut As New Mutex(True, "myuniquemutexname", firstInstance)

If firstInstance Then
Try
' start your main form
Application.Run(New MainForm())
Catch
' Handle problems
Finally
' make sure the mutext is released
mut.ReleaseMutex()
End Try
Else
MessageBox.Show("App already running")
End If
End If

Just make sure that "myuniquemutexname" is unique and known to your
program. A mutex is a global kernel object, and so can be referenced by
all applications by using the unique name. If your application is given
ownership of the mutex, then firstInstance will be true - otherwise,
your app is already running :)


Nov 20 '05 #4
In article <eh**************@TK2MSFTNGP10.phx.gbl>, Shawn D Shelton wrote:
Tom,

Is using the Mutex a more efficient or better way than doing it like this?

I place the following code in the Public Sub New() of the form code

Try
Dim StrProcessName As String
StrProcessName = Diagnostics.Process.GetCurrentProcess.ProcessName
If Diagnostics.Process.GetProcessesByName(StrProcessN ame).Length > 1 Then
'More than one instance was found
AppActivate(StrProcessName)
End
End If
Catch
'do nothing
End Try
thank you!

Shawn Shelton


I'm not sure that there is anything terribly wrong with your way... I
tend to use a mutex because it used to be a fairly standard way of
accomplishing this task doing raw win32 programming... Also, because
mutex's are global sync objects, you aren't going to run into any issues
with timing.

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #5
* Shawn D Shelton <sh******@isu.edu> scripsit:
Is using the Mutex a more efficient or better way than doing it like this?

I place the following code in the Public Sub New() of the form code

Try
Dim StrProcessName As String
StrProcessName = Diagnostics.Process.GetCurrentProcess.ProcessName
If Diagnostics.Process.GetProcessesByName(StrProcessN ame).Length > 1 Then
'More than one instance was found
AppActivate(StrProcessName)
End
End If
Catch
'do nothing
End Try


This may return wrong results if there are different applications with
the same name running on the machine.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #6
In article <bo*************@ID-208219.news.uni-berlin.de>, Herfried K. Wagner [MVP] wrote:
* Shawn D Shelton <sh******@isu.edu> scripsit:
Is using the Mutex a more efficient or better way than doing it like this?

I place the following code in the Public Sub New() of the form code

Try
Dim StrProcessName As String
StrProcessName = Diagnostics.Process.GetCurrentProcess.ProcessName
If Diagnostics.Process.GetProcessesByName(StrProcessN ame).Length > 1 Then
'More than one instance was found
AppActivate(StrProcessName)
End
End If
Catch
'do nothing
End Try


This may return wrong results if there are different applications with
the same name running on the machine.


Ah, didn't think about that... Good catch ;)
--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
6902
by: Ross Presser | last post by:
OK, I've been researching this problem and can't find a definitive answer yet. The situation is one that seems to have come up a few times to different folks. I am writing an application that...
4
10326
by: Bill Dika | last post by:
Hi I am trying to calculate a running total of a calculated textbox (tbAtStandard) in GroupFooter1 for placement in a textbox (tbTotalAtStandard) on my report in Groupfooter0. The problem...
1
5752
by: Ennio-Sr | last post by:
Hi all! Testing a script where I need to make sure that postgresql is running before passing a <psql dbasename -c "insert into ..." > instruction I faced this curious behaviour: This is the...
1
5992
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the...
7
1786
by: pradeep_TP | last post by:
hello all, I want to know how can I check whether a web site us running or not. I have used HttpWebRequest but when I give a web site address, It takes few number of seconds to throw exception...
3
1547
by: Anil Kumar Sharma | last post by:
Hello, I am working on C# using vs.net 2003. I have faced two interesting problems. 1. Dynamically setting Default Button: I created a form and used it in various contexts. On basis of the...
4
4158
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
16
11270
by: Gandalf186 | last post by:
I need to create a query that produces running totals for every group within my table for example i wish to see: - Group A 1 5 9 15 Group B
2
4634
by: upperclass | last post by:
Hi, I'm trying to find a decent way to measure program running time. I know clock() is probably the standard way of doing it but clock_t overflows too quickly. The target program running time...
1
8118
by: =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?= | last post by:
On reflection, you could possibly make the app a self extracting zip file which extracts the EXE and a settings file and then starts the app, then when you app closes, it can repack the settings...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.