Run the application once
-
Hi all, I have created one windows setup application,when i installed it on the system if i click two times the application is running two times as it should run once. How can i solve it ? Thanks in advance.
You should run your app using the Mutex class, something like this:-
bool isNew = true;
using (Mutex mutex = new Mutex(true, "yourAppName", out isNew))
{
if (isNew)
{
Application.Run(new MainForm());
}
}If the app is aplready running and you would like it to be given focus you need to use a Win32 API method called
SetForegroundWindow
which I'm sure you could find an instance of on Google. Hope this helpsWhen I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
-
You should run your app using the Mutex class, something like this:-
bool isNew = true;
using (Mutex mutex = new Mutex(true, "yourAppName", out isNew))
{
if (isNew)
{
Application.Run(new MainForm());
}
}If the app is aplready running and you would like it to be given focus you need to use a Win32 API method called
SetForegroundWindow
which I'm sure you could find an instance of on Google. Hope this helpsWhen I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
-
Thanks!
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
-
Hi all, I have created one windows setup application,when i installed it on the system if i click two times the application is running two times as it should run once. How can i solve it ? Thanks in advance.
Here 5+ alternatives Run Only One Copy Of Application[^]
thatraja
My Dad had a Heart Attack on this day so don't...
Pompeyboy3 here | Nobody remains a virgin, Life screws everyone :sigh: -
Hi all, I have created one windows setup application,when i installed it on the system if i click two times the application is running two times as it should run once. How can i solve it ? Thanks in advance.
WARNING: all the schemes that have been mentioned to you do not prevent the app from launching a second or third time; all they do is try and make the app terminate pretty soon if it isn't the first instance. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Hi all, I have created one windows setup application,when i installed it on the system if i click two times the application is running two times as it should run once. How can i solve it ? Thanks in advance.
CP has many articles on making a "Singleton" app:[^]
When I consider the brief span of my life, swallowed up in the eternity before and after, the little space which I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which knows me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then.
Blaise Pascal
-
WARNING: all the schemes that have been mentioned to you do not prevent the app from launching a second or third time; all they do is try and make the app terminate pretty soon if it isn't the first instance. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
Luc Pattyn wrote:
all the schemes that have been mentioned to you do not prevent the app from launching a second or third time
Even the one from Wayne G. using a Mutex ? thanks, Bill
When I consider the brief span of my life, swallowed up in the eternity before and after, the little space which I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which knows me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then.
Blaise Pascal
-
Luc Pattyn wrote:
all the schemes that have been mentioned to you do not prevent the app from launching a second or third time
Even the one from Wayne G. using a Mutex ? thanks, Bill
When I consider the brief span of my life, swallowed up in the eternity before and after, the little space which I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which knows me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then.
Blaise Pascal
It still has to start to detect that there's another instance running. It's not that they don't stop the appearance of an app not being started again, but there will always be a finite period of time where the second instance has spun up - even if it then terminates.
Forgive your enemies - it messes with their heads
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility