Pergunta

I am working in a desktop application created in java. we are working for windows version (for running on windows O.S.) of the application. When we run our application, it creates a tray icon on desktop by using systemtray as

SystemTray tray = SystemTray.getSystemTray();

I am creating single instance of the system tray, which I am creating in the main class of the application.

I am creating exe for my application. My problem is when i am running the exe file of my application, it creates tray icon every time.

I want in my application only one tray icon present on desktop and running as a service. this icon should only get removed, when application is uninstalled. It should run as service in the background.

I am not getting any way which will help me to run my application as a service and there should be only one instance running in the background.

I want to run my application by creating a tray icon as a service and should have single instance present. Please guide me in this issue.

Thanks for your all valuable suggestions in advance.

Foi útil?

Solução

As Mudassir said, you should add a check when you start your program that tries to find another running instance of your app. This could be done by creating a specific file upon startup, and deleting it on close. If the file is already present when you start your app, it means that another instance is running. You could also use inter-process communications, but it would be more difficult than a simple file.

For the "service" part, you could hide the main window on startup, so your app will run as if it was a windows service.

Outras dicas

Make your application Single Instance. And please tell how you are making an .EXE file in Java?

For a tray icon to appear, your app must be running. If your tray icon appears to be there twice (or more), than your application runs multiple times. You have to add a check for this yourself.

You don't want to run your app as a windows service, as normally these have no access to the Windows Desktop.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top