Page 1 of 1

Another way to avoid calling app multiple times

Posted: Tue Apr 04, 2017 11:41 pm
by Pablo César
Time passes and with it we finish maturing the ideas, the techniques employed.

The example of using wapi_CreateMutex and IsExeRunning is pretty much the same.
The only difference I see is that one is called by the function in Harbour and the other by a function in C in the HMG.
Both in my opinion are expendable for practical use.

In my opinion, it does not make sense to check if the application is already running without taking such a limited action as telling the user that the application is already running only.

IsExeRunning function in HMG IMHO can be improved by adding a optional parameter that indicates if it wants to return the handle of the window that was already running. This way we could bring forward the window by restoring and making focus, after then to close the second instance.

It can even remains minimized and use FlashWindowEx function if we so desire.

I have prepared this example by comparing 4 options for your evaluation and who knows if the idea could be improved or at least be adopted for HMG:
<Attached files was removed because there is a newest version more ahead of this same topic>
What do you think ? (Run twice each option and compare)

Could you give me your opinion, which option would be most convenient to use ?

I have already chosen:  #3   :D

Re: Ejecutar una sola vez la aplciación

Posted: Wed Apr 05, 2017 8:53 am
by serge_girard
Nice job Pablo,

Can you please explain how WINDOW Demo6 works. I see no DEFINE WINDOW...?

And how about killing the running EXE? In case the program got hung up (infinite loop or something). Case 3 is best option but then it will bring you back to the EXE you can't get to stop or rerun.


Re: Ejecutar una sola vez la aplciación

Posted: Wed Apr 05, 2017 11:36 am
by Pablo César
Hi Serge, thank for your interest and you are very kind. :)

Sorry I forgot to attach Demo6.fmg file.  :oops:   It's a simple form and without window's title.

I've adapted the new IsExeRunning2 function to keep retrocompatibility with the current IsExeRunning function. Returning as default, logical value if the current application is already being run in another instance. And when the second parameter was passed, it would return the handle of the instance that was already open.

So, I updated here in attached files:
Executable file (updated)
(1.21 MiB) Downloaded 88 times
Source files (updated)
(1.45 KiB) Downloaded 82 times
In that way, we would have a IsExeRunning function improved by IsExeRunning2.
Improved in my criteria for these reasons:
  1. In the same way as IsExeRunning, IsExeRunning2 function does not need SET MULTIPLE OFF.
  2. IsExeRunning2 function works with full name of application. What means that application's full path is being included and it's what ensures that will not confuses with other application with the same name to be different one.
    For example: If app with location+name C:\App1\Demo.exe is running and in another instance (other session) other app with location+name C:\App2\Demo.exe be in trying to run... certainly it will be guaranteed. Because this last application even that is with same names are also at different places.
  3. The IsExeRunning2 function is able to return a preexisting instance identifier of the same application. Behaving differently than IsExeRunning if informed .T. As new and second parameter.
    This will allow the programmer to use the handle of the pre-existing instance and manipulate the focus resumption. If the window is minimized, it would restore it and bring it to the front for focus. If the other instance is behind you would only bring it forward and focus.
  4. Keep retrocompatibility with the pre-existing IsExeRunning function in HMG.
Continuing to answer your questions Serge...
And how about killing the running EXE?
You do not have to kill any process. Just check if it has another session running this same application.
If it is, it only exits (it exits with RETURN) and if not it finds: it continues the application normally.
In case the program got hung up (infinite loop or something)
If got hung up, systems should start again. Because this function is not tied to any temporary file (as it has proposed or indicated by Carlos RD).
IsExeRunning2 it is similar in the aspect of checking app running names. But improved in the way it's done.
Case 3 is best option but then it will bring you back to the EXE you can't get to stop or rerun.
Yes, you will decide what to do if other session is in running in duplication...

Please note that this Demo6 minimizes the window just to simulate that the user left it minimized and tried twice open the app.

Re: Ejecutar una sola vez la aplciación

Posted: Wed Apr 05, 2017 11:59 am
by Pablo César
Dear Rathinagiri,

Could you do me the favor of moving my messages from this topic and Serge's last ones (if he does not show discomfort).
I did not note it was in the Spanish session and would like it to be part of a new topic in "HMG Tutorials and Tips".
I then add in the topic in Spanish a message indicating the link of my new indications.
I want to do this on the grounds that I want something more generalized (Mostly by the title. It's also wrongly write in spanish too) and because I consider that I have not expressed myself in Spanish what I prefer to do in the Spanish section.

I appreciate your providence in advance.
I intend to use this same message by re-editing and to indicate a new link for the new topic in Spanish language.

Sorry for the inconvenience.

Re: Ejecutar una sola vez la aplciación

Posted: Wed Apr 05, 2017 12:52 pm
by serge_girard
No problemo, amigo (Correcto senor?)

Re: Ejecutar una sola vez la aplciación

Posted: Wed Apr 05, 2017 12:56 pm
by Pablo César
I know nothing... no-thing... I'm from Barzzzzzelona... :lol: :D

Thank, Serge for allowing messages moving..

Re: Ejecutar una sola vez la aplciación

Posted: Wed Apr 05, 2017 2:02 pm
by Pablo César
Hi all,

Please note, at my previous message was re-edited, new version was replaced in attached files.

Retro-compatibilization: upper case was forced to cExeName.

Option #4 was added to demonstrates that is retro-compatible.

Re: Ejecutar una sola vez la aplciación

Posted: Thu Apr 06, 2017 6:36 am
by Rathinagiri
I moved the whole topic to HMG Tutorials and Tips.

You have to give a title for this topic.

Post in Spanish section a new topic if you want.