|
Previous Top Next |
This templates makes it easy to prevent multiple instances of the program from executing at the same time.
Unique Program String | This is a string that you create and is unique to this program. You could use the Core Class Demo to create a GUID if you want to use a string that you can be pretty safe will be unique. Just remember that once you assign it to the program you should never change it if you want to make 100% sure that your program will always be unique and never run more than one instance on any computer. If you need to run multiple instances of the program, but each with a different setting (for example different command line parameters) you can use a variable for this and set it to something unique for each instance. Because this code executes right after the program CODE statement, you could use a simple source function to get the unique string. Here is an example of a very simple source procedure: GetProgramID PROCEDURE (String pID)!!,String S CString(100) Code S = Clip(pID) If Command(1) S = S & Command(1) End Return(S) To use this, you put in: ! GetProgramID('MyProgram') to the "Unique program string" entry. Note the exclamation mark at the beginning. It is required to make the template interpret it as not being a string constant. You could of course also let the GetProgramID() procedure construct the whole string and just use GetProgramID() to get the string. |
Window caption string | This string is used to find the running instance on the computer and then activate it. |
Activate Running... | Check this if you want to activate the running instance of the program when the user tries to run it again. |
Show Message | Check this if you want to show a message when a second instance is found. |
Message Caption | Caption for the message to display. |
Message Text | Text for the message to display. |
Note that you can use variables for any of the text entries by using ! in front of the name. Anything else will be interpreted as a literal string. You do not have to put single quotes around string literals, the template will do that automatically when generating the code.
The code is generated right after the CODE statement for the program. There are 5 embed points created by this template in a tree node called "Icetips | Limit Program Instance" so you can add code before and after the generated code, as well as before the Message(), before the window is activated and before the HALT() so you do have some flexibility. You can also use the method described above for the Unique Program String and use that function to do any program initialization you want to complete before the program validation is performed.
See also: