472,794 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

Identify multiple running instances of an application

Hi, I wrote an app in .Net and I whant only 1 instance of this app open for
the user; the user open my app, do some works and try to open another
instance of my app, I whant to show a message to user to inform him that only
one instance is permit and then close the second instance after that.

I am able to do this when the user run the application on his PC whit this :

Process.GetProcessesByName(Process.GetCurrentProce ss.ProcessName)

and if I found the name of my app in the returned collection, I display the
message and close the seconde instance.

The problem now: if my application is used by Remote session on a central PC
who others users can also open my application at the same time, I would like
to let the others users open my app. The only one contrainte is one instance
by user. The code I used does not work in this scenario.

Does anyone have idea to solution this ?

Thanks a lot
Michel
Mar 13 '06 #1
3 2482
If you know the name of the process you can do something like this

using System.Diagnostics;
if (Process.GetProcessesByName(processName).Length > 0)
return true;
// where processName is the process you are looking for.
The other option is; you can use a Mutex and verify if the Mutex already
exists.

--------------------
Thread-Topic: Identify multiple running instances of an application
thread-index: AcZGp1JCRsO2yAK6TdOQEauDPYg6Nw==
X-WBNR-Posting-Host: 66.38.186.253
From: =?Utf-8?B?TWljaGVs?= <Mi****@discussions.microsoft.com>
Subject: Identify multiple running instances of an application
Date: Mon, 13 Mar 2006 06:06:28 -0800
Lines: 21
Message-ID: <32**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
Newsgroups: microsoft.public.dotnet.general
Path: TK2MSFTNGXA03.phx.gbl
Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:191032
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.dotnet.general

Hi, I wrote an app in .Net and I whant only 1 instance of this app open forthe user; the user open my app, do some works and try to open another
instance of my app, I whant to show a message to user to inform him that onlyone instance is permit and then close the second instance after that.

I am able to do this when the user run the application on his PC whit this :
Process.GetProcessesByName(Process.GetCurrentProc ess.ProcessName)

and if I found the name of my app in the returned collection, I display themessage and close the seconde instance.

The problem now: if my application is used by Remote session on a central PCwho others users can also open my application at the same time, I would liketo let the others users open my app. The only one contrainte is one instanceby user. The code I used does not work in this scenario.

Does anyone have idea to solution this ?

Thanks a lot
Michel


--

Thank You,
Nanda Lella,

This Posting is provided "AS IS" with no warranties, and confers no rights.

Mar 13 '06 #2
Hi Nanda, thank you for your answer. Your code will work but the problem I
have is how to find the process used by a specific user. Many users can
connect by remote sessions on a computer to run my application. I whant to
restrict 1 instance by user. The code you suggest to me can find the process
(my app) of another user connected remotly to the computer, and I don't whant
it... is it possible to do this ? I don't know.... :(

thank you for your help....

Michel

"Nanda Lella[MSFT]" wrote:
If you know the name of the process you can do something like this

using System.Diagnostics;
if (Process.GetProcessesByName(processName).Length > 0)
return true;
// where processName is the process you are looking for.
The other option is; you can use a Mutex and verify if the Mutex already
exists.

--------------------
Thread-Topic: Identify multiple running instances of an application
thread-index: AcZGp1JCRsO2yAK6TdOQEauDPYg6Nw==
X-WBNR-Posting-Host: 66.38.186.253
From: =?Utf-8?B?TWljaGVs?= <Mi****@discussions.microsoft.com>
Subject: Identify multiple running instances of an application
Date: Mon, 13 Mar 2006 06:06:28 -0800
Lines: 21
Message-ID: <32**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
Newsgroups: microsoft.public.dotnet.general
Path: TK2MSFTNGXA03.phx.gbl
Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:191032
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.dotnet.general

Hi, I wrote an app in .Net and I whant only 1 instance of this app open

for
the user; the user open my app, do some works and try to open another
instance of my app, I whant to show a message to user to inform him that

only
one instance is permit and then close the second instance after that.

I am able to do this when the user run the application on his PC whit this

:

Process.GetProcessesByName(Process.GetCurrentProc ess.ProcessName)

and if I found the name of my app in the returned collection, I display

the
message and close the seconde instance.

The problem now: if my application is used by Remote session on a central

PC
who others users can also open my application at the same time, I would

like
to let the others users open my app. The only one contrainte is one

instance
by user. The code I used does not work in this scenario.

Does anyone have idea to solution this ?

Thanks a lot
Michel


--

Thank You,
Nanda Lella,

This Posting is provided "AS IS" with no warranties, and confers no rights.

Mar 14 '06 #3
Hello Michel,

If you use Mutex then you can restrict a single instance per user.
Also you can create a global Mutex to restrict single instance per machine.

using System.Threading;
Mutex processMutex = new Mutex(false,"Your Application Name");
if (processMutex.WaitOne(0, false) == false)
{
//Multiple intstance detected.
}//if

//Approach 2
using System.Threading;
bool isFirstInstance;
Mutex processMutex = new Mutex(true, "Your Application Name", out
isFirstinstance);
if(!isFirstInstance)
{
//Multiple instance detected.
}//

//If you plan to do one instance per machine create the mutex this way
Mutex processMutex = new Mutex(true, "Global\\" + "Your Application Name",
out isFirstinstance);

The important point to note is dont forget to release/dispose the mutex
when there is an error or when you are done with the applications. Best
place is to do the mutex release in the finally block.
if (processMutex != null)
{
processMutex.Close();
processMutex = null;
}//if
Hope this helps,
--------------------
Thread-Topic: Identify multiple running instances of an application
thread-index: AcZHbJn8ROGT6iGXT1KtfXVgY7xLYQ==
X-WBNR-Posting-Host: 66.38.186.253
From: =?Utf-8?B?TWljaGVs?= <Mi****@discussions.microsoft.com>
References: <32**********************************@microsoft.co m> <xS**************@TK2MSFTNGXA03.phx.gbl>Subject: RE: Identify multiple running instances of an application
Date: Tue, 14 Mar 2006 05:38:39 -0800
Lines: 86
Message-ID: <79**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
Newsgroups: microsoft.public.dotnet.general
Path: TK2MSFTNGXA03.phx.gbl
Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:191137
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.dotnet.general

Hi Nanda, thank you for your answer. Your code will work but the problem I
have is how to find the process used by a specific user. Many users can
connect by remote sessions on a computer to run my application. I whant to
restrict 1 instance by user. The code you suggest to me can find the process(my app) of another user connected remotly to the computer, and I don't whantit... is it possible to do this ? I don't know.... :(

thank you for your help....

Michel

"Nanda Lella[MSFT]" wrote:
If you know the name of the process you can do something like this

using System.Diagnostics;
if (Process.GetProcessesByName(processName).Length > 0)
return true;
// where processName is the process you are looking for.
The other option is; you can use a Mutex and verify if the Mutex already
exists.

--------------------
>Thread-Topic: Identify multiple running instances of an application
>thread-index: AcZGp1JCRsO2yAK6TdOQEauDPYg6Nw==
>X-WBNR-Posting-Host: 66.38.186.253
>From: =?Utf-8?B?TWljaGVs?= <Mi****@discussions.microsoft.com>
>Subject: Identify multiple running instances of an application
>Date: Mon, 13 Mar 2006 06:06:28 -0800
>Lines: 21
>Message-ID: <32**********************************@microsoft.co m>
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="Utf-8"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>Content-Class: urn:content-classes:message
>Importance: normal
>Priority: normal
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
>Newsgroups: microsoft.public.dotnet.general
>Path: TK2MSFTNGXA03.phx.gbl
>Xref: TK2MSFTNGXA03.phx.gbl microsoft.public.dotnet.general:191032
>NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
>X-Tomcat-NG: microsoft.public.dotnet.general
>
>Hi, I wrote an app in .Net and I whant only 1 instance of this app open

for
>the user; the user open my app, do some works and try to open another
>instance of my app, I whant to show a message to user to inform him
that only
>one instance is permit and then close the second instance after that.
>
>I am able to do this when the user run the application on his PC whit
this :
>
>Process.GetProcessesByName(Process.GetCurrentProc ess.ProcessName)
>
>and if I found the name of my app in the returned collection, I display

the
>message and close the seconde instance.
>
>The problem now: if my application is used by Remote session on a
central PC
>who others users can also open my application at the same time, I would

like
>to let the others users open my app. The only one contrainte is one

instance
>by user. The code I used does not work in this scenario.
>
>Does anyone have idea to solution this ?
>
>Thanks a lot
>Michel
>


--

Thank You,
Nanda Lella,

This Posting is provided "AS IS" with no warranties, and confers no rights.


--

Thank You,
Nanda Lella,

This Posting is provided "AS IS" with no warranties, and confers no rights.

Mar 14 '06 #4

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

Similar topics

1
by: Mark McKay | last post by:
I've been reading 'Java RMI' from O'Reilly, and it provides a nice example of scaling a server application by creating multiple instances of server objects on several distinct machines (each...
6
by: Chris Tyson | last post by:
I created an Access 97 database a while ago. It is protected by Workgroup Security, and it is not split. In order to compare different sets of results, a colleague has suggested that it would be...
0
by: RonNanko | last post by:
Hi, let me first explain what my problem is all about: I have a third-party application, which does not allow multiple instances of itself. As I need to run the application in multiple instances...
11
by: Clark Stevens | last post by:
I just finished a WinForms app in VB.NET. I want to allow the user to be able to run multiple instances of the program like you can with Notepad and Wordpad. The way it is now, once I run the...
4
by: hotmit | last post by:
I'm trying to create a program that dynamicly saves and loads path of a FolderBrowserDialog , but I ran into a problem. Since FolderBrowserDialog is not a Control, therefore it doesn't have...
0
by: rbg | last post by:
Have a web application which uses Data Cache. I need to understand what happens when a new instance of the same web application is created for for serving concurrent clients. What happens when...
2
by: Job Lot | last post by:
How can I prevent multiple instances of a C# windows forms application. VB.NET provides My.Application.StartupNextInstance Event to do this. Is there any C# equivalent as well? Thanks
1
balabaster
by: balabaster | last post by:
Hi, I'm trying to figure out how to install multiple instances of a Windows Service on a single machine using the deployment Setup Project. We have a Windows Service that's configurable through...
3
by: =?Utf-8?B?VG9kZA==?= | last post by:
What is the memory footprint of static methods of a windows app running on a server when the server spins up multiple instances of the application? In my envirionment, we have a Citrix server...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.