I am working on WinForms. Now I want to implement one thing: when I will click on the desktop application’s shortcut, and then the application is in a minimized state, then it will open from system tray (not create a new instance).
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Okay so when you double-click the shortcut, that will actually open another instance of the application, which has no knowledge of the one already running minimised to the tray.
Essentially you want to detect that another instance of your app is running on startup. If it is, tell the existing instance of your app to show it’s UI to the user, then quit.
Your solution consists of two things:
1. The ability for your app to understand that another instance of it is already running.
This is simple in .NET. When you app opens, use the
Mutexclass. This is a system-wide lock, otherwise similar in nature toMonitor.Example:
2. Inter-process communication
There are a few methods for doing IPC in .NET. WCF is one, though quite heavy. Named pipes is probably the best choice for you, although it’s such a simple requirement that basic socket messaging should also work.
Here’s a link to a question on appropriate IPC methods in .NET to help you out: What is the best choice for .NET inter-process communication?