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

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - rottenapple

我遇到的Sqlserver2005 SSIS 的Bug SSIS导入Oracle中的性能问题 Excel内容不能正确倒入SSIS? 使用Oracle Generic Connectivity连接SqlServer asp.net下的用户权限管理模块设计 msdn也出现这种错误。。。 为Log4Net添加异常处理模块 - rottenapple - 博客园 ibatis.net的配置文件设计 今天发现了ibatis.net的一个bug The Visual Studio template information is out of date. asp.net 设计中的页面流程控制的一点想法(讨论贴) - rottenapple - 博客园 New job,New chance 使用强类型DataSet的好处 在Framework1.0下同时连接SqlServer和Oracle的一些体会 VS2002 与 IIS6.0的一个bug 利用WSDL2JAVA实现JAVA调用.Net的Web Services(1) T_SQL中的事务处理 SqlCommand的ExecuteNonQuery()方法执行多条T-SQL语句 博客园的Bug
如何使应用程序只有一个实例在运行
rottenapple · 2005-08-05 · via 博客园 - rottenapple

上网搜索了一下,发现大家都提到了一个方法,使用Mutex类,但是其中有个问题很多人没有遇到。
就是如果项目文件很大的话,Mutex 对象在编译的时候可能会被当成垃圾给释放掉。
[STAThread]
    static void Main()                  // args are OK here, of course
    {
        bool ok;
        m = new System.Threading.Mutex(true, "YourNameHere", out ok);

        if (! ok)
        {
            MessageBox.Show("Another instance is already running.");
            return;
        }

        Application.Run(new Form1());   // or whatever was there

        GC.KeepAlive(m);                // important!
    }

其中GC.KeepAlive()必须有,原因如下:
We want the program to keep hold of the mutex as long as it's running. But the JIT compiler sees that the mutex is only used near the beginning of the program, and may discard it prematurely when memory is needed for something else!