我想在单个辅助角色中执行多个操作.如何在worker角色中创建线程?
您可以在WorkerRole :: OnStart()中添加多个worker,如此处所述
http://www.31a2ba2a-b718-11dc-8314-0800200c9a66.com/2010/12/running-multiple-threads-on-windows.html
原文链接:https://www.f2er.com/windows/365175.htmlpublic 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); } } }