| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 603 人关注过本帖
标题:[讨论]怎么修改当前程序实例?
取消只看楼主 加入收藏
amingo
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2004-8-27
收藏
 问题点数:0 回复次数:1 
[讨论]怎么修改当前程序实例?

using System.Diagnostics;

using System.Reflection;

public static Process RunningInstance()

{

Process current = Process.GetCurrentProcess();

Process[] processes = Process.GetProcessesByName(current.ProcessName);

//Loop through the running processes in with the same name

foreach (Process process in processes)

{

//Ignore the current process

if (process.Id != current.Id)

{

//Make sure that the process is running from the exe file.

if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName)

{

//Return the other process instance.

return process;

}

}

}

//No other instance was found, return null.

return null;

}

系统Main函数
if( RunningInstance() == null )

Application.Run(new yourFormName());

我用上面这种方法让程序只能产生一个实例,
我想做的是:如果程序已经运行,把它弹出并显示到最前面。

怎么实现 望高手指点!

搜索更多相关主题的帖子: Process 实例 processes using 
2006-04-04 22:17
amingo
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2004-8-27
收藏
得分:0 
这个群的人水平很有限啊!
2006-04-04 22:51
快速回复:[讨论]怎么修改当前程序实例?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011886 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved