通过 C# 实现任务并行,一次执行 10 个任务,例如 100 个类似任务

发布于 2024-12-28 19:38:46 字数 203 浏览 6 评论 0原文

我在托管 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空宴 2025-01-04 19:38:46

您可以使用最大计数为 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

阳光的暖冬 2025-01-04 19:38:46

是的,这绝对是可能的。有关设置延续的信息,请参阅此 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文