Another way to avoid calling app multiple times

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Another way to avoid calling app multiple times

Post 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
Last edited by Pablo César on Fri Apr 07, 2017 2:11 pm, edited 2 times in total.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Ejecutar una sola vez la aplciación

Post 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.

Serge
There's nothing you can do that can't be done...
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Ejecutar una sola vez la aplciación

Post 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:
Demo6_Exe.rar
Executable file (updated)
(1.21 MiB) Downloaded 299 times
Demo6.rar
Source files (updated)
(1.45 KiB) Downloaded 290 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.
Last edited by Pablo César on Wed Apr 05, 2017 3:30 pm, edited 10 times in total.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Ejecutar una sola vez la aplciación

Post 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.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Ejecutar una sola vez la aplciación

Post by serge_girard »

No problemo, amigo (Correcto senor?)
There's nothing you can do that can't be done...
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Ejecutar una sola vez la aplciación

Post by Pablo César »

I know nothing... no-thing... I'm from Barzzzzzelona... :lol: :D

Thank, Serge for allowing messages moving..
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Ejecutar una sola vez la aplciación

Post 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.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Ejecutar una sola vez la aplciación

Post 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.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply