Another way to avoid calling app multiple times

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Another way to avoid calling app multiple times

Post by Pablo César » Tue Apr 04, 2017 11:41 pm

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: 1838
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 279 times
Been thanked: 63 times
Contact:

Post by serge_girard » Wed Apr 05, 2017 8:53 am

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

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Wed Apr 05, 2017 11:36 am

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 50 times
Demo6.rar
Source files (updated)
(1.45 KiB) Downloaded 47 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: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Wed Apr 05, 2017 11:59 am

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: 1838
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 279 times
Been thanked: 63 times
Contact:

Post by serge_girard » Wed Apr 05, 2017 12:52 pm

No problemo, amigo (Correcto senor?)

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Wed Apr 05, 2017 12:56 pm

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: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Wed Apr 05, 2017 2:02 pm

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: 5166
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 129 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Thu Apr 06, 2017 6:36 am

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