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

5

12

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

Jokester answered 29/5, 2009 at 20:35 Comment(0)
P
4

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.

Pyrite answered 29/5, 2009 at 20:49 Comment(1)
Link seems to be broken.Palp
S
1

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.

Seriocomic answered 29/5, 2009 at 20:49 Comment(0)
F
1

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.

Fuqua answered 29/5, 2009 at 21:0 Comment(0)
L
0

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.

Lowney answered 29/5, 2009 at 20:49 Comment(1)
Java's Executor can do much more than that. See java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/… for example.Seriocomic
D
0

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

Dakotadal answered 16/6, 2018 at 18:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.