Page 1 of 3

Starting App from a netfolder

Posted: Sun Sep 16, 2018 6:25 pm
by ROBROS
Hi friends,
there is a very useful function "IsAppRunning()" in hmg. It prevents me to launch an app, that's already running. But, it won't work on a netfolder, at least that is what I have experienced. If I am wrong, tell me and do not continue reading.
The reason why I came to hmg (thank you Roberto Lopez), was, I had some small apps with UI like "from date"-"to date" (mostly reports). I did them all with xbase++ in text mode and excel made them "good-looking". xbase++ is powerful, but I did never try to go GUI. Too difficult for a non professional like me.
In the meantime almost all my apps were rewritten to hmg (professional look and feel, people saying: "hey, he's gone windows"). But then I created an app, that really needs GUI. With the help from this forum it is done to 99%. For me 2 weeks are left to go up to 100%. I will. :lol:

This app is on a netfolder to which 3-4 users have access. To prevent, that more than 1 user can start the program I came to the following solution:
Any time the program is launched, the field "username" in a table is replaced by "GetComputerName()" and the program can not be started. When the program is finished, "username" is replaced with spaces.
Before I realize that, has anyone a better suggestion?

I'm looking forward to your suggestions.
Robert

Re: Starting App from a netfolder

Posted: Sun Sep 16, 2018 7:03 pm
by edk

Re: Starting App from a netfolder

Posted: Sun Sep 16, 2018 7:13 pm
by ROBROS
Ok,

sounds promising...
I will try.. At home I have no network environment.

Robert

Re: Starting App from a netfolder

Posted: Sun Sep 16, 2018 8:07 pm
by edk
ROBROS wrote: Sun Sep 16, 2018 6:25 pm This app is on a netfolder to which 3-4 users have access. To prevent, that more than 1 user can start the program I came to the following solution:
Any time the program is launched, the field "username" in a table is replaced by "GetComputerName()" and the program can not be started. When the program is finished, "username" is replaced with spaces.
Before I realize that, has anyone a better suggestion?

I'm looking forward to your suggestions.
Robert
edk wrote: Sun Sep 16, 2018 7:03 pm Maybe try this: http://hmgforum.com/hmgdoc/data/setmultiple.htm
ROBROS wrote: Sun Sep 16, 2018 7:13 pm Ok,

sounds promising...
I will try.. At home I have no network environment.

Robert
I'm sorry, Robert, but I did not read your post until the end.
This "SET MULTIPLE ON | OFF [ WARNING ]" functionality does not allow twice running application for the same user, so there will be no solution for your problem.
If I understand correctly, do not you want the application to be able to run more than one user at the same time?
It seems to me that a better solution will be to open dummy dbf in exclusive mode. If you can not open dbf in this mode, it will mean that it is being used by another user.
Your solution has one drawback, when any error occurs in the program, you may find that the field with the computer name will not be changed to empty and then the application will be "blocked" and unavailable to anyone.
My solution is not burdened with this risk, because in case of error the exclusive mode will be automatically released.

Regards, Edward.

Re: Starting App from a netfolder

Posted: Sun Sep 16, 2018 11:20 pm
by apais
Hi ROBROS

Create a dummy dbf and open it exclusive or exit.
This way only 1 user can be logged in at a time.

HTH
Angel

PD: This is call "semaphore". Youcan use it to sync processes among multiple users, apps, threads, ...

Re: Starting App from a netfolder

Posted: Mon Sep 17, 2018 5:52 am
by dragancesu
Or change database, move to MySQL

Re: Starting App from a netfolder

Posted: Mon Sep 17, 2018 10:06 am
by PeteWG
Hi,
probably the most quick (and not dirty, I hope, yet quite strict and inflexible), might be this line of code alone:

Code: Select all

hb_vfOpen( hb_ProgName(), 16 )
Put it on top of your Main() procedure and let the OS be responsible
that only one user at a time will be able to run the program.

It's similar to "semaphore" proposition made by Angel, but it doesn't require
a dummy dfb or something. It's kind of a "self-semaphore-ization" ;)

Note: I have not tested it, but see no reason to not works as expected.
Warning: Be sure your users do not used to have a "two-three hours coffee break", leaving the program running! :-)



regards,
Pete

_____________________________________________________________________________
- “Sir, I exist!”
- “However”, replied the Universe, “the fact has not created in me a sense of obligation”.
(Stephen Crane)

Re: Starting App from a netfolder

Posted: Mon Sep 17, 2018 10:15 am
by dragancesu
if you want to work with dbf, ensure that each application is unique, the users (and password) table, the login () function and the table where you keep track of who is logged in
You need to make sure you know who logged in

Re: Starting App from a netfolder

Posted: Mon Sep 17, 2018 3:23 pm
by franco
Another thought. if you have a table called ? check or something. It is a dummy table with 1 field. At start of program lock the table and
when closing the program unlock the table. If the table is locked make code that program in use, try later.
Franco

Re: Starting App from a netfolder

Posted: Mon Sep 17, 2018 6:58 pm
by ROBROS
Hi friends,
wow, how many replies and each one of quality. I am just glad to have access to hmg-forum. :D

Just keep in mind: I am not a professional programmer. :(

@Edward (edk): I am aware of the drawback, I would give a responsible person a possibility to empty that field. My intention to go this way is simply to avoid "error-handling", I have no experience with that. :cry:
@angel and pete: semaphore is new to me, thank you. hb_vfOpen() is a harbour function?
@dragancesu: can I create sql-apps with hmg?
@franco: thank you, is similar, yet not equal to what I had in mind.

Thank you very much.
Robert