472,980 Members | 1,661 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,980 software developers and data experts.

Check whether an application is running

pnp
What's the best way to check whether an app is running so if one tries to
open it again it will not open a second instance of the application but will
give focus to the already open one maximizing it...

-Peter
Nov 16 '05 #1
3 9051
In article <uw**************@TK2MSFTNGP09.phx.gbl>, "pnp" <pnp.at.softlab.ece.ntua.gr>
says...
What's the best way to check whether an app is running so if one tries to
open it again it will not open a second instance of the application but will
give focus to the already open one maximizing it...

-Peter

Try this in your main...

=====================================

System.Threading.Mutex appMutex = new System.Threading.Mutex(true,"AppName");

if(appMutex.WaitOne(0, false))
{
try
{
Application.Run(new FormMain());
}
catch(Exception EX)
{
MessageBox.Show("Application Error!!\r\n" + EX.Message);
}

}
else
{

MessageBox.Show("The application is already loaded.");
}
=====================================
Nov 16 '05 #2
pnp
thanks John.

"John Nelson" <ne**@scapeware.com> wrote in message
news:MP************************@news.comcast.gigan ews.com...
In article <uw**************@TK2MSFTNGP09.phx.gbl>, "pnp" <pnp.at.softlab.ece.ntua.gr> says...
What's the best way to check whether an app is running so if one tries to open it again it will not open a second instance of the application but will give focus to the already open one maximizing it...

-Peter
Try this in your main...

=====================================

System.Threading.Mutex appMutex = new

System.Threading.Mutex(true,"AppName");
if(appMutex.WaitOne(0, false))
{
try
{
Application.Run(new FormMain());
}
catch(Exception EX)
{
MessageBox.Show("Application Error!!\r\n" + EX.Message);
}

}
else
{

MessageBox.Show("The application is already loaded.");
}
=====================================

Nov 16 '05 #3
"John Nelson" <ne**@scapeware.com> wrote in message
news:MP************************@news.comcast.gigan ews.com...
System.Threading.Mutex appMutex = new System.Threading.Mutex(true,"AppName");
if(appMutex.WaitOne(0, false))
{
try
{
Application.Run(new FormMain());
}
catch(Exception EX)
{
MessageBox.Show("Application Error!!\r\n" + EX.Message);
}

}
else
{

MessageBox.Show("The application is already loaded.");
}
=====================================


I use something similar to this pretty much in every WinForms app I write as
a replacement for the old VB "App.PrevInstance()" function if I need to
prevent more than one instance of the app running...
Nov 16 '05 #4

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

Similar topics

4
by: Dr. StrangeDub | last post by:
I am part of a group that has developed an ASP.Net web application. I am looking for a way to determine whether or not the browser is actually running on the web server. For this case (when...
1
by: James | last post by:
I am creating a system whereby equipment is inspected. Data is inputted into an inspection form. However, any equipment that is not satisfactory needs to have spare parts ordered for that piece of...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
1
by: kiran | last post by:
How to check whether the given application is running or not in the current machine. From, my cshartp program I want check whether the yahoo messenger process is running ro not..? if the process is...
8
by: Neil Robbins | last post by:
I'd like to know how to check whether another application is running in Windows on the same computer from my application so I can perform an action if it is. Could anyone suggest where helpful...
12
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...
9
by: Michael.Suarez | last post by:
Suppose I have a program that prompts you with a dialogbox to enter a password. If you get the password correct, it allows you into the program, else it kills the program. Suppose that when I...
1
by: keri | last post by:
Hi, I use the below for the user to view their outlook calendar Sub DisplayInbox() Dim myolApp As Outlook.Application Dim myNameSpace As Outlook.NameSpace Dim myFolder As Outlook.MAPIFolder...
9
by: fniles | last post by:
I am using VB.NET 2005. To check if the same program already run or not, I can use the following If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length MsgBox("Another...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 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
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.