惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security Blog

博客园 - 流泉飞石

转:ADO.Net Entity Framework : (七) 多條件查詢 转载:GridView 空记录时显示 Header 代码重构相关书籍 转:恢复Reflector反编译后资源文件的办法 WPF 回车转Tab实现跳转 C#自定义快捷键实现介绍 C#中自定义快捷键【转载】 转:[WPF] WPF资源收集 分享 转:.NET开发人员必知的八个网站 WatermarkComboBox 和 WatermarkTextBox 转:c#中线程访问winform控件的若干问题 [转] DotNet资源站点汇总 DataKeyNames工作 - 流泉飞石 - 博客园 转:功能很强大的UIHelper类 转:动态修改webservice地址 转:CS结构软件自动升级实现 几个很好的url重写工具 asp.net获取应用程序路径 - 流泉飞石 - 博客园 SqlServer 查询sql执行时间
C#程序多用户只启动一个进程的方法[转载]
流泉飞石 · 2009-12-30 · via 博客园 - 流泉飞石

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://greenlandy.blogbus.com/logs/14388828.html

Code Snippet

  1. [STAThread]
  2.      private static void Main()
  3.      {
  4.          Application.EnableVisualStyles();
  5.          Application.SetCompatibleTextRenderingDefault(false);
  6.          var wb = new Form1();
  7.          Process current = Process.GetCurrentProcess();
  8.          bool newinstance = true;
  9.          Process[] processes = Process.GetProcessesByName(current.ProcessName);
  10.  
  11.          //?历正在有相同名字??的例程  
  12.          foreach (Process process in processes)
  13.          {
  14.              //忽略现有的例程  
  15.              if (process.Id != current.Id)
  16.              {
  17.                  //确保例程从EXE文件??  
  18.                  if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName)
  19.                  {
  20.                      //?回另一个例程实例  
  21.                      current = process;
  22.                      newinstance = false;
  23.                      break;
  24.                  }
  25.              }
  26.          }
  27.          if (newinstance)
  28.          {
  29.              Application.Run(wb);
  30.          }
  31.          else
  32.          {
  33.              ShowWindowAsync(current.MainWindowHandle, 1);
  34.  
  35.              //?置真实例程为foreground   window  
  36.              SetForegroundWindow(current.MainWindowHandle);
  37.          }
  38.      }

引入这两个API函数

Code Snippet

  1. [DllImport("User32.dll")]
  2. private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
  3.  
  4. [DllImport("User32.dll")]
  5. private static extern bool SetForegroundWindow(IntPtr hWnd);

posted @ 2009-12-30 16:06  流泉飞石  阅读(842)  评论()    收藏  举报