Question

Are there any differences between:

Dim Block As New TransformBlock(Of Integer, Integer)(Function(_i)
                                                     //sync proccessing
                                                       Return j
                                                     End Function)

And

   Dim Block As New TransformBlock(Of Integer, Integer)(Async Function(_i)
                                                       Return Await something
                                                     End Function)

Even if I use a Sync delegate, setting MaxDegreeOfParallelerism of block affects its perfomance. So, as I get it, block makes a Task(Of T) from its sync delegate and works with its instances.

Which of this variants preferably to use?

Was it helpful?

Solution

Use the asynchronous delegate when you have naturally-asynchronous work to do (e.g., I/O-bound).

Use the synchronous delegate when you have naturally-synchronous work to do (e.g., CPU-bound).

Neither one is "better;" it just depends on what kind of work you need to do.

OTHER TIPS

Since the delegate is running on a new worker thread, I am wondering if async delegate or sync delegate will have too much difference on performance.

For example, the sync delegate is reading a large file and since it is running on a worker thread, it will not block the main thread either.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top