WCF 和线程任务

发布于 2024-08-16 01:21:23 字数 297 浏览 5 评论 0原文

我想使用 WCF 编写一些 Web 服务。

我想在我的网络服务中有一个“线程池”。 例如,我有近 6GB 的数据需要操作。

我希望客户端调用 Web 服务上的操作并创建一个新任务或线程。客户端可以调用ListRunningTasks();并让网络服务返回任务列表。如果任务花费太长时间,客户端应该能够强制终止任务,例如 KillTask​​(int taskID);或其他什么。我之前做过一些线程处理,但不是在 WCF 或没有状态的服务内。这可能吗?如果是这样,人们将如何实施这样的事情?任何阅读、链接或建议都会很棒。

谢谢,迈克。

I am wanting to write some web services using WCF.

I would like to have a "thread pool" in my web service.
For example, I have nearly 6gb of data I need to manipulate.

I would like the client to call an operation on the webservice and have a new task or thread created. The client is able to call a ListRunningTasks(); and have the webservice return a list of tasks. The client should be able to forcefully kill a task if it is taking too long e.g. KillTask(int taskID); or something. I have previously done some threading, but not inside WCF or a service that doesn't have state. Is this possible? If so, how would one go about implementing such a thing? Any reading, links or suggestions would be great.

Thanks, Mike.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

烟沫凡尘 2024-08-23 01:21:23

一种可能的解决方案:

  • 为未完成的任务实现显式队列,考虑到它们需要那么长时间(如您所写,为 20-30 分钟)。

  • 构建一个自定义组件来管理这些队列,例如您甚至可能需要持久保存它们的功能,重新启动服务时恢复工作等。

    构建

  • 已显式创建从这些队列中提取工作的工作线程。

  • 实现 WCF 服务,使您的队列管理器可供外部系统使用。

线程池更适合处理大量短期运行的任务。

One possible solution:

  • Implement explicit queues for your outstanding tasks taking into consideration that they take that long (20-30mins as you wrote).

  • Build a custom component to manage those queues e.g. you might even want capabilities to persist them, resume work when you restart the service etc.

  • Have explicitly created worker threads that pickup work from those queues.

  • Implement a WCF service to make your queue manager available to external systems.

Thread pools are more designed to process a high volume of short-running tasks.

故人的歌 2024-08-23 01:21:23

您应该考虑使用 Windows Workflow Foundation创建这样的服务。状态机工作流可以公开为服务,当方法 A 被调用时,它将启动工作流(任务),之后可以调用方法来停止、挂起或查询正在运行的任务。 WF 将处理状态转换,防止非法状态更改,并确保仅在必要时启动新任务。

请注意,WF 将以几乎透明的方式为您处理线程问题。

You should consider using Windows Workflow Foundation to create such services. A state machine workflow can be exposed as a service in such a way that when method A is called, it will start the workflow (task), after which methods can be called to stop, suspend, or query the running task. WF will handle the state transitions, preventing illegal state changes, and making sure that new tasks are only spun up as necessary.

Note that WF will handle the threading issues for you in an almost transparent manner.

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