Home » U++ Library support » TopWindow&PopUp, TrayIcon » How to check whether application is running
Re: How to check whether application is running [message #27922 is a reply to message #27877] |
Tue, 10 August 2010 21:28 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
The *recommended* (by M$) way of detecting other instances of application is using of named mutex. Making mutex is much cheaper and much more atomic operation than creating window. Why is that important?
Imagine you have system with many programs running. And your program makes some complex initialization prior to creating window (i.e. reading XML configuration, constructing objects, etc.)
User runs your app. But OS is busy, it starts swapping. Your app is actually started, but user doesn't see any window, because your app is still initializing (please note that creating window is very resource consuming operation, especially for "busy" OS).
What happens next? User thinks that he did something wrong and executes your app again. This is problem #1.
The problem #2 arises next. Your app which was started second checks window (remember that window of the first app is not finished it's creation), doesn't find it and creates it's own window as if it is the first.
If you think this is rare situation, I must admit it is not. Multitasking can be hard sometimes. And app #2 can potentially be initialized even BEFORE app #1.
That is all why we should use much cheaper and quicker operation in the program start instead of checking opened window.
Let's return to recommended scheme:
1. Check mutex with name "*****"
2. If exists, exit app. If not - immediately create one and start app.
3. Important: all initialization should be done AFTER (1) and (2).
I don't know which is POSIX recommended way. I think our POSIX specialists may consult us.
|
|
|
|
|
How to check whether application is running
By: bushman on Mon, 09 August 2010 03:59
|
|
|
Re: How to check whether application is running
By: bushman on Mon, 09 August 2010 04:16
|
|
|
Re: How to check whether application is running
|
|
|
Re: How to check whether application is running
By: bushman on Mon, 09 August 2010 05:18
|
|
|
Re: How to check whether application is running
|
|
|
Re: How to check whether application is running
By: unodgs on Tue, 10 August 2010 22:47
|
|
|
Re: How to check whether application is running
By: kohait00 on Fri, 13 August 2010 16:21
|
|
|
Re: How to check whether application is running
By: Alboni on Wed, 16 January 2013 12:29
|
|
|
Re: How to check whether application is running
By: lectus on Wed, 16 January 2013 14:38
|
|
|
Re: How to check whether application is running
By: Alboni on Wed, 16 January 2013 15:44
|
|
|
Re: How to check whether application is running
|
|
|
Re: How to check whether application is running
By: lectus on Fri, 18 January 2013 01:56
|
|
|
Re: How to check whether application is running
|
|
|
Re: How to check whether application is running
By: Alboni on Wed, 16 January 2013 17:38
|
|
|
Re: How to check whether application is running
By: Alboni on Wed, 16 January 2013 18:01
|
|
|
Re: How to check whether application is running
By: BioBytes on Wed, 16 January 2013 21:32
|
Goto Forum:
Current Time: Thu May 09 02:02:54 CEST 2024
Total time taken to generate the page: 0.02353 seconds
|