通过 C# 实现任务并行,一次执行 10 个任务,例如 100 个类似任务
我在托管 Window 服务中有 WCF 服务。一次可以有多个服务请求通过asp.net网页(例如100个请求)来访问该服务。我正在 WCF 服务中应用锁定,因为我遇到了其他问题。由于我正在应用锁定,因此当我对其进行负载测试时,请求超时。是否可以运行 10 个并行任务,并且当每个任务完成时,应该为剩余 90 个任务创建并执行新任务。我正在尝试优化我的内存,这样我就不需要增加 WCF 的超时
I have WCF service in a managed Window service. There can be several service request through asp.net web page at a time (say 100 requests) to access this service. I am applying lock in the wcf service as i was facing some other issue. Since i am applying lock the request is getting timed out when i load test it. Is it possible to run 10 parallel task and as each tasks get completed new tasks should be created and executed for the remaining 90 tasks. i am trying to optimize my memory and also that way i need not increase the timeouts for my WCF
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用最大计数为 10 的信号量来代替锁
http://msdn.microsoft.com/en-us/library/system.threading.semaphore.aspx
Instead of a lock, you could use a semaphore with a maximum count of 10
http://msdn.microsoft.com/en-us/library/system.threading.semaphore.aspx
是的,这绝对是可能的。有关设置延续的信息,请参阅此 MSDN 文档:
http://msdn.microsoft.com/en-us/ library/dd537612(VS.110).aspx
(我假设“任务”指的是任务并行库中的任务对象)
Yes, this is definitely possible. See this MSDN document on setting up continuations:
http://msdn.microsoft.com/en-us/library/dd537612(VS.110).aspx
(I am assuming by "Task" you are referring to the Task object in the Task Parallelism Library)