您的位置:首页 > 编程语言 > C#

c# 多线程 创建跨进程的EventWaitHandle 源码

2011-07-13 09:50 405 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
class AUTO
{
static EventWaitHandle ev = new AutoResetEvent(false);
static EventWaitHandle EW = new AutoResetEvent(false);
static volatile string tack="a";
static void Main()
{
new Thread(new ThreadStart(work)).Start();
for(int i=1;i<=5;i++)
{
ev.WaitOne();
tack=tack.PadRight(i, 'h');
EW.Set();
}

ev.WaitOne(); tack = null; EW.Set();
Console.ReadLine();
}

static void work()
{
while (true)
{
ev.Set();
EW.WaitOne();
if (tack == null) return;
Console.WriteLine(tack);

}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: