single instance and notify in system tray

◇◆丶佛笑我妖孽 提交于 2019-12-18 17:31:20

问题


I am working on the application (C# 2.0). I have implemented single instance in it. Everything is fine. If i run the application again, it shows messagebox saying "instance is already running".

Actually i don't want to show the message through messagebox.

I want to show this message using Balloon tip of already running instance (it has notify icon in system tray).

How can i achieve this?

Thanks in advance.


回答1:


You need a form of interprocess communication, to signal to the other instance that it should display the messagebox.

In this instance, you could go one better than telling the existing instance to display the message, and instead tell it to restore it's main window (i.e. "unminimise").




回答2:


You could use a WCF service inside you app.

Your second app connects to it via NetPipe, invode a method and closes.

Your first app receive the call and pops-up the baloon notification




回答3:


The easiest way to implement a single instance and to inform the first one if a second is started is already implement in .Net. Just take a look into the following links:

Hanselman: Single Instance WinForms

OpenWinForms (select True Single Instance application)




回答4:


The CodeFluent Runtime which is free set of tools provides a SingleInstance class to implement a single instance application:

You've just to override the WndProc method to pops-up your notification (Baloon tip).



来源:https://stackoverflow.com/questions/1255834/single-instance-and-notify-in-system-tray

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