Controlling the Number of Application Instances
Tuesday October 9, 2007
in Advanced Delphi ::
In this article you'll learn how to "run-once" enable a Delphi application that can check for its previous (running) instance. Along the process, several techniques of implementing such a check will be discussed; as well as how to bring your already running application to the foreground, if a user tries to run it "one more time". By the end of the article you'll have a copy-to-go code to control the behavior of your application's multiple instances: with the option to limit the number of running instances.
In this article you'll learn how to "run-once" enable a Delphi application that can check for its previous (running) instance. Along the process, several techniques of implementing such a check will be discussed; as well as how to bring your already running application to the foreground, if a user tries to run it "one more time". By the end of the article you'll have a copy-to-go code to control the behavior of your application's multiple instances: with the option to limit the number of running instances.
Read the full article to learn how to Control the Number of Application Instances.
Related:

I am surprised no one ever considers the simple solution. I have been using it for years and you are welcome to the code. Basically, it consists of trying to delete a file that might be called Mult.txt. You then write it and open it, so that the next instance will fail to delete it as the operating system will not allow such an operation. This isn’t quite how it works as I wrote it 10 years ago and I suspect many other have done the same. I could write it up, if there is any interest.
This screams for a class helper for TApplication. Try it, much cleaner…
Adrian, we are always interested in different ways of solving something!
Thaddy, class helpers are available only to Delphi versions > 7