Is there a .Net equivalent to java.util.concurrent.Executor?

无人久伴 提交于 2019-12-09 14:53:10

问题


Have a long running set of discrete tasks: parsing 10s of thousands of lines from a text file, hydrating into objects, manipulating, and persisting.

If I were implementing this in Java, I suppose I might add a new task to an Executor for each line in the file or task per X lines (i.e. chunks).

For .Net, which is what I am using, I'm not so sure. I have a suspicion maybe CCR might be appropriate here, but I'm not familiar enough with it, which is why I pose this question.

Can CCR function in an equivalent fashion to Java Executors, or is there something else available?

Thanks


回答1:


You may want to look at the Task Parallel Library.

As of C# 5 this is built into the language using the async and await keywords.




回答2:


If you're going to ask a bunch of .NET people what's closest to being equivalent to Java Excecutors, it might not hurt to describe the distinguishing features of Java Executors. The person who knows your answer may not be any more familiar with Java than you are with .NET.

That said, if the already-mentioned Task Parallel Library is overkill for your needs, or you don't want to wait for .NET 4.0, perhaps ThreadPool.QueueUserWorkItem() would be what you're looking for.




回答3:


Maybe this is related: Design: Task Parallel Library explored. See 10-4 Episode 6: Parallel Extensions as a quick intro.

For older thread-based approach, there's ThreadPool for pooling.




回答4:


The BackgroundWorker class is probably what you're looking for. As the name implies, it allows you to run background tasks, with automatically managed pooling, and status update events.




回答5:


For anyone looking for a more contemporary solution (as I was), check out the EventLoopScheduler class.



来源:https://stackoverflow.com/questions/928018/is-there-a-net-equivalent-to-java-util-concurrent-executor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!