473,394 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 9074
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.