Single instance application...

Posted on 2004-11-26
Last Modified: 2010-03-31
I have developed an application that takes custumized protocol links from a web page. I had to write a registry key to invoke the program but I have succeded.

Here is the scenario:
just like http, ftp, and ed2k links, I have written a registry key so that if a URL in a web page contains a specific protocol lets say "myapp" as in
<a href="myjavaapp://|parameter_1|......|parameter_n|">Click here</a>
"myjavaapp" is invoked and from the link above receives the parameters.

My Problem:
If "myjavaapp" is not running there is no problem. The application is started.
If "myjavaapp" is already running a new instance of the program is run. So I have two copies of the same program running on my desktop.
What should I do to make this program run in one instance? I have been told to create a file on startup of the application and delete when exited, but incase my application crashes the file would not be deleted, thus if I check the existanse of that file, since it would exist from a previous crash, the application would not run.

So what should I do other than "creating and deleting a file upon start and exit" option?
Question by:DigiTechin
    LVL 18

    Accepted Solution

    Hi DigiTechin,
    this may help

    LVL 18

    Expert Comment


    Author Comment


    I already seen those. They both talk about locking a file, which is not what I intend to do.
    My problem resides. If the program crashes, for one reason or another, I would get stuck.
    LVL 24

    Assisted Solution

    That's not true: a lock vanishes if the program stops!
    LVL 18

    Expert Comment

    sciuriware is write the lock finishes..
    the other option is open a serverSocket, That is also the same as locking a file.
    LVL 24

    Expert Comment

    Thanks for your support armoghan, but please say "sciuriware is right" in stead of "write"
    otherwise I feel a file myself.
    I found that the file locking works on all platforms in the world and has
    some advantages: the locker can write some identification in the lock file.
    That means that, again system independent, the system manager can findout
    where such a file belongs to: it's very hard to find socket-locks in a living system.
    One application: can you take a system down, knowing that all locking applications
    have left? From the socket-method you couldn't tell; from the lock-method you can.
    LVL 18

    Expert Comment

    hahaha .
    Thanx for correcting
    Sorry sciuriware

    My english is not that good and I scramble words while writing

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    classnotfoundexception 3 28
    powerN  challenge 3 36
    IT Company 5 56
    DO we need Java installed on a Windows PC and WHY ? 13 31
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now