博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2011年6月10日

摘要: using System;using System.Threading;public class Example{ // A semaphore that can satisfy at most two concurrent // requests. // private static Semaphore _pool = new Semaphore(2, 2); public static void Main() { // Create and start two threads, A and B. // Thread tA = new Thread(new ThreadStart(Threa 阅读全文

posted @ 2011-06-10 15:48 hyruur 阅读(1303) 评论(1) 推荐(0) 编辑

摘要: 实现方式一: 使用线程互斥变量. 通过定义互斥变量来判断是否已运行实例.C#实现如下:把program.cs文件里的Main()函数改为如下代码:static void Main(){bool runone;System.Threading.Mutex run = new System.Threading.Mutex(true, "jiaao_test", out runone);if (runone){run.ReleaseMutex();Application.EnableVisualStyles();Application.SetCompatibleTextRende 阅读全文

posted @ 2011-06-10 10:46 hyruur 阅读(620) 评论(1) 推荐(0) 编辑