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

一笑奈何 提交于 2019-11-30 23:16:59

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.

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.

Luiz E.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!