How to restrict Eclipse-RCP application to a single instance?

后端 未结 4 2019
生来不讨喜
生来不讨喜 2021-01-06 12:04

I would like to restrict my Eclipse-RCP application to a single instance. By this, I mean that once a user opens the application for the first time, it listens on a port and

相关标签:
4条回答
  • 2021-01-06 12:26

    I have an app that does this same thing. The trick is that the new instance can't bring the old instance to the front. But, the old instance can bring itself to the front after it contacts the new instance.

    So your old instance needs to call

    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
    

    after it notifies the new instance. For my app, the new instance doesn't show an error message, it just closes transparently and the old instance pops itself back up.

    0 讨论(0)
  • 2021-01-06 12:28

    Basically you can have functionality like eclipse. Eclipse maintains a .lock file to lock the workspace. You can similarly create an empty .lock file in your workspace.

    On starting every instance, you should check if .lock file is present and then proceed further accordingly. If file is not present you should create it so that other instance will find that workspace is locked.

    0 讨论(0)
  • 2021-01-06 12:29

    i think you should just alternate to you already running instance.
    i don't know if this or this link could help, but thats all i got

    really hope it helps

    0 讨论(0)
  • 2021-01-06 12:34

    Have a look at this article: Single instance of RCP application. The author describes the same pattern of using a server socket which you are asking about.

    0 讨论(0)
提交回复
热议问题