.net – 如何在Windows azure worker角色中创建多个线程

前端之家收集整理的这篇文章主要介绍了.net – 如何在Windows azure worker角色中创建多个线程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在单个辅助角色中执行多个操作.如何在worker角色中创建线程?
您可以在WorkerRole :: OnStart()中添加多个worker,如此处所述 http://www.31a2ba2a-b718-11dc-8314-0800200c9a66.com/2010/12/running-multiple-threads-on-windows.html
public class WorkerRole : ThreadedRoleEntryPoint
    {
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("Worker Role entry point called","Information");

            base.Run();
        }

        public override bool OnStart()
        {
            List<WorkerEntryPoint> workers = new List<WorkerEntryPoint>();

            workers.Add(new ImageSizer());
            workers.Add(new ImageSizer());
            workers.Add(new ImageSizer());
            workers.Add(new HouseCleaner());
            workers.Add(new TurkHandler());
            workers.Add(new Crawler());
            workers.Add(new Crawler());
            workers.Add(new Crawler());
            workers.Add(new Gardener());
            workers.Add(new Striker());

            return base.OnStart(workers.ToArray());
        }
    }



   internal class Striker : WorkerEntryPoint
    {
        public override void Run()
        {
            while (true)
            {
                // Do Some Work

                Thread.Sleep(100);
            }
        }
    }
原文链接:https://www.f2er.com/windows/365175.html

猜你在找的Windows相关文章