473,322 Members | 1,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 473,322 software developers and data experts.

One instance only

I created a simple exe program in c#. I would like to run one instance of
the program at a time. if i click the exe after the program is already
opened it should NOT start a new instance of the program it should set focus
to the currently running program.

Thanks
Aaron
Nov 15 '05 #1
5 8264
Use the Process class to examine running processes to determine if your app
is running ...

HTH,

Alex

"Aaron" <ku*****@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I created a simple exe program in c#. I would like to run one instance of
the program at a time. if i click the exe after the program is already
opened it should NOT start a new instance of the program it should set focus to the currently running program.

Thanks
Aaron

Nov 15 '05 #2
can you give me an example?

"Trebek" <tr****@nospam.com> wrote in message
news:84********************@fe3.columbus.rr.com...
Use the Process class to examine running processes to determine if your app is running ...

HTH,

Alex

"Aaron" <ku*****@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I created a simple exe program in c#. I would like to run one instance of the program at a time. if i click the exe after the program is already
opened it should NOT start a new instance of the program it should set

focus
to the currently running program.

Thanks
Aaron


Nov 15 '05 #3
Take a look at the mutex class.

Yves

"Aaron" <ku*****@yahoo.com> schreef in bericht
news:%2****************@tk2msftngp13.phx.gbl...
I created a simple exe program in c#. I would like to run one instance of
the program at a time. if i click the exe after the program is already
opened it should NOT start a new instance of the program it should set focus to the currently running program.

Thanks
Aaron

Nov 15 '05 #4
"Aaron" <ku*****@yahoo.com> writes:
I created a simple exe program in c#. I would like to run one instance of
the program at a time. if i click the exe after the program is already
opened it should NOT start a new instance of the program it should set focus
to the currently running program.


using System.Threading;

public class blah
{
public static void main(string[] args)
{
// the first instance of this program will
// create a mutex and its waitone returns
// true so, the other instances will get false
Mutex mutex = new Mutex(false, "blah");
if(mutex.WaitOne(1, false) == false)
return;
}
}

--
Lawrence "Rhymes" Oluyede
http://loluyede.blogspot.com
Nov 15 '05 #5
My Windows Forms Tips and Tricks page covers this.

http://www.bobpowell.net/tipstricks.htm
--
Bob Powell [MVP]
C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Aaron" <ku*****@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I created a simple exe program in c#. I would like to run one instance of
the program at a time. if i click the exe after the program is already
opened it should NOT start a new instance of the program it should set focus to the currently running program.

Thanks
Aaron

Nov 15 '05 #6

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

Similar topics

34
by: SeeBelow | last post by:
I see the value of a class when two or more instances will be created, but Python programmers regularly use a class when there will only be one instance. What is the benefit of this? It has a...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
6
by: Hemant Shah | last post by:
Folks, I need to move HOME directory of an instance to another directory. What is the best way of doing it? Is changing password file enough? or dies DB2 store this info in it's own config? ...
6
by: Dmitry Karneyev | last post by:
Hi! I guess this question have been asked a lot of times, but please be tolerant and if you have any ideas share it. The question is: how to make availibale only one instance of application and...
7
by: Göran Tänzer | last post by:
Hi, i've written a class which does some calculations for my web application. These informatinos are different for each page request - the current user is not important. i have about 10 aspx...
2
by: TEK | last post by:
Hello We're having a issue with a part of our app that is very strange, and I'm unable to see that it should be possible. We have: A collection (ActivityCollection) that is inherited from a...
13
by: JohnQ | last post by:
Why would anyone write: class SomeThing // class littered with non-domain single-instancing code :( { private: SomeThing(); static SomeThing* pInstance_; public: static SomeThing*...
12
by: titan nyquist | last post by:
I have a class with data and methods that use it. Everything is contained perfectly THE PROBLEM: A separate thread has to call a method in the current instantiation of this class. There is...
19
by: =?Utf-8?B?Sko=?= | last post by:
I have a logging component that I will access in other assemblies. So it was brought up to me that I should pass an instance around to these components instead of just making the logging class...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.