就是运行第一个实例程序后到托盘,再运行同一个程序的第二个实例,不会再运行这个实例程序,只是把第一个实例主界面显示出来。
求助 怎么实现。
求助 怎么实现。
解决方案 »
- 新手求救:<VS2010 连接 SQL Server 2008 连接不上>
- .net 里有没有能生成apr1 md5密码加密方式的方法啊
- c#网页调试出错
- DataRow 怎么添加到顶部 就是一行数据出现到上面呢?
- 进来个帮我看下面这个方法命名是什么意思`
- C# 如何设定定时器才能先运行一下程序再开始Interval
- 请问程序关闭事件是哪个谢谢
- 带工作组的access数据库,用OLE DB来连接,连接字符串怎么写?
- 明天要去法国安盛集团(北京)面试了,要求穿正装。请问:现在的天气,穿什么样的正装呀?对于我这样一个28岁的大小伙子来说,穿什么好呢
- 报表中碰到的几个棘手的问题?
- c#传真,faxcomexlib.dll下载
- Sql Server 事务提交报错“请求没有对应的 BEGIN TRANSACTION”,但是能执行成功。
2,如果是,缩小到托盘
3,如果不是,向另一线程发送打开主界面的消息,并且关闭自身发送的方法有很多,API的SENDMESSAGE,或者自定义程序通讯(WINSOCK,写文件,等等)
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd);
private const int SW_RESTORE = 9; public void RaiseOtherProcess()
{
Process proc = Process.GetCurrentProcess();
Process.GetProcesses();
foreach (Process otherProc in
Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName))
{
//ignore "this" process
if (proc.Id != otherProc.Id)
{
// Found a "same named process".
// Assume it is the one we want brought to the foreground.
// Use the Win32 API to bring it to the foreground.
IntPtr hWnd = otherProc.MainWindowHandle;
if (IsIconic(hWnd))
{
ShowWindowAsync(hWnd, 9);
}
SetForegroundWindow(hWnd);
break;
}
}
}
还是用mutex实现互斥。
当互斥发生时调用以上代码,实现:
2.如果程序已经存在,且最小化,则还原那个程序。
3.如果程序已经存在,且不是最小化(最大化或正常状态),则显示(注意:不是还原!)那个程序。
其实你主要是不知道可以用这个方法:SetForegroundWindow(hWnd);
来显示程序。
http://zhidao.baidu.com/question/116698008.html
{
string name = Process.GetCurrentProcess().ProcessName;
int id = Process.GetCurrentProcess().Id;
Process[] prc = Process.GetProcesses();
foreach(Process pr in prc)
{
if ((name == pr.ProcessName) && (pr.Id != id))
{
MessageBox.Show("对不起,本地已经有系统正在运行!\n.","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
System.Environment.Exit(0);
}
}