M
Mario
I have a C# app that runs script files. The app is launched using a
command line argument to indicate which script should run. Most
scripts are run indefinitely in a loop and periodically perform tasks.
When the script is launched the Title Bar of the app indicates the name
of the app and the name of the script being run.
I thought to use a GetProcessesByName to return all instances of the
app and then to check the MainWindowTitle of each process to identify
that a script is running more than one instance. This almost works.
When the app is minimized, it runs in the system tray and the
MainWindowTitle returns and empty string.
While it is not difficult to prevent multiple instances of the app from
launching this is not the desired effect. The app may kick off any
number of instances. What matters is that the same script file is not
running under more than one instance of the app.
I realize I could record state information in a database or in a file
and check it upon launching the app, but there are timeliness issues
related to this approach -- the app may be too involved doing other
tasks to take the necessary time to update the state information for at
least several moments. Therefore, this approach is not
up-to-the-second accurate.
I considered checking scripts in and out. However, an abnormal
termination of the app may not properly check in a script as available.
Any ideas for making sure that only one instance of the app is running
any given script file?
Mario T. Lanza
Clarity Information Architecture, Inc.
2005.11
command line argument to indicate which script should run. Most
scripts are run indefinitely in a loop and periodically perform tasks.
When the script is launched the Title Bar of the app indicates the name
of the app and the name of the script being run.
I thought to use a GetProcessesByName to return all instances of the
app and then to check the MainWindowTitle of each process to identify
that a script is running more than one instance. This almost works.
When the app is minimized, it runs in the system tray and the
MainWindowTitle returns and empty string.
While it is not difficult to prevent multiple instances of the app from
launching this is not the desired effect. The app may kick off any
number of instances. What matters is that the same script file is not
running under more than one instance of the app.
I realize I could record state information in a database or in a file
and check it upon launching the app, but there are timeliness issues
related to this approach -- the app may be too involved doing other
tasks to take the necessary time to update the state information for at
least several moments. Therefore, this approach is not
up-to-the-second accurate.
I considered checking scripts in and out. However, an abnormal
termination of the app may not properly check in a script as available.
Any ideas for making sure that only one instance of the app is running
any given script file?
Mario T. Lanza
Clarity Information Architecture, Inc.
2005.11