小编Tom*_*azy的帖子

c#中信令线程的性能

我一直试图理解"唤醒"正在等待阻塞构造的线程需要多长时间AutoResetEvent- 从我在阅读多个讨论之后理解的是,窗口有某种内部时钟,每15.6ms"滴答"一次(左右)然后决定下一个计划运行哪些线程,所以我希望在线程发出信号直到该线程唤醒之间的时间差需要0-15.6ms之间的随机时间.所以我写了这个小程序来测试我的理论:

static void Main(string[] args)
        {
            double total = 0;
            int max = 100;
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            for (int i = 0; i < max; i++)
            {                
                AutoResetEvent eventHandle = new AutoResetEvent(false);
                double time1 = 0;
                double time2 = 0;
                Thread t1 = new Thread(new ThreadStart(() => time1 = f1(stopwatch, eventHandle)));
                Thread t2 = new Thread(new ThreadStart(() => time2 = f2(stopwatch, eventHandle)));
                t1.Start();
                t2.Start();
                t1.Join();
                t2.Join();
                double diff = time2 - time1;
                total += …
Run Code Online (Sandbox Code Playgroud)

c# performance stopwatch autoresetevent

4
推荐指数
1
解决办法
150
查看次数

标签 统计

autoresetevent ×1

c# ×1

performance ×1

stopwatch ×1