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

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
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
"如果程序已经运行,把它弹出并显示到最前面。"
它指的是什么?什么才叫最前面?

<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2006-04-04 22:19
一直很安静
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2006-3-31
收藏
得分:0 
不是吧,我都听得懂,就是form1本身已经运行,但是后来又调用form2,现在想把form1放在显示的最前端啊

qq:33534255
2006-04-04 22:40
amingo
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2004-8-27
收藏
得分:0 
这个群的人水平很有限啊!
2006-04-04 22:51
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
以下是引用一直很安静在2006-4-4 22:40:00的发言:
不是吧,我都听得懂,就是form1本身已经运行,但是后来又调用form2,现在想把form1放在显示的最前端啊

这样就设置form1的topmost属性为true啊。


<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2006-04-05 19:08
快速回复:[讨论]怎么修改当前程序实例?
数据加载中...
 
   



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

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