Solution to see if program is already running.
Posted: Fri Dec 24, 2010 12:15 am
There was, i think Rev. Bloedel that was asking for feature to see if another incident of hollywood program is already running. Unfortunately i went on to delete that post right away after reading, and after clicking that delete button, it came to my mind that i would have some sort of soltuion for that problem.
This how you can do it.
Everytime you start the program, you first check if there is this "check.dat" file in the folder you start the program from.
If it doesnt exist, then it means there is no other incident of the same program running already.
IN which case you create the "check.dat" file.
After you close the program, then you will before closing program delete that "check.dat" file.
Naturally there is possibility that computer have crashed and hence "check.dat" file is still there, so in case it is there, you need to give user the option to start the program anyway, although your simple test thinks there already is one incident runnning.
You can also make more sophisticated versions of this. LIke you could make "check.dat" file to contain number of incidents runnning. that:
n = readfile("check.dat")
n = n + 1
writefile(n, "check.dat")
and similarly on closing n = n - 1
This how you can do it.
Everytime you start the program, you first check if there is this "check.dat" file in the folder you start the program from.
If it doesnt exist, then it means there is no other incident of the same program running already.
IN which case you create the "check.dat" file.
After you close the program, then you will before closing program delete that "check.dat" file.
Naturally there is possibility that computer have crashed and hence "check.dat" file is still there, so in case it is there, you need to give user the option to start the program anyway, although your simple test thinks there already is one incident runnning.
You can also make more sophisticated versions of this. LIke you could make "check.dat" file to contain number of incidents runnning. that:
n = readfile("check.dat")
n = n + 1
writefile(n, "check.dat")
and similarly on closing n = n - 1