|
-
Apr 26th, 2013, 10:04 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] TPL Data Flow: MSDN example not compiling
Hi Guys,
I'm trying to run the MSDN example here http://msdn.microsoft.com/en-us/library/hh228601.aspx and am getting compile errors. I was hoping someone could look at the attached project DataFlowTest.zip and let me know what I'm doing wrong.
Basically it seems that an extension method isn't recognized by the editor.
I get the error:
'OutputAvailableAsync' is not a member of 'System.Threading.Tasks.Dataflow.ISourceBlock(Of Byte())
However, it's there: http://msdn.microsoft.com/en-us/library/hh160369.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
And of course, it's used in the MSDN example.
Thanks,
Nick
-
Apr 26th, 2013, 10:13 AM
#2
Re: TPL Data Flow: MSDN example not compiling
OutputAvailableAsync is an extension method. It's a member of the DataflowBlock class, declared in the System.Threading.Tasks.Dataflow.dll assembly and a member of the System.Threading.Tasks.Dataflow namespace. Have you referenced that assembly in your project and imported that namespace in you code file? Also, are you targeting .NET 4.5, because that method didn't exist in earlier versions?
-
Apr 26th, 2013, 10:16 AM
#3
Addicted Member
Re: TPL Data Flow: MSDN example not compiling
 Originally Posted by nickwrs
Hi Guys,
I'm trying to run the MSDN example here http://msdn.microsoft.com/en-us/library/hh228601.aspx and am getting compile errors. I was hoping someone could look at the attached project DataFlowTest.zip and let me know what I'm doing wrong.
Basically it seems that an extension method isn't recognized by the editor.
I get the error:
'OutputAvailableAsync' is not a member of 'System.Threading.Tasks.Dataflow.ISourceBlock(Of Byte())
However, it's there: http://msdn.microsoft.com/en-us/library/hh160369.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
And of course, it's used in the MSDN example.
Thanks,
Nick
Double Check what framework your using. ISourceBlock looks like is only supported in 4.5
-
Apr 26th, 2013, 10:53 AM
#4
Thread Starter
Hyperactive Member
Re: TPL Data Flow: MSDN example not compiling
Hi Guys,
4.5 is the frame work, and referenced the System.Threading.Tasks.Dataflow assembly in my project and imported it in the code file.
If someone has some free time I attached the entire project to the post. But, here is the code from the page:
Code:
Imports System
Imports System.Threading.Tasks
Imports System.Threading.Tasks.Dataflow
' Demonstrates a basic producer and consumer pattern that uses dataflow.
Friend Class DataflowProducerConsumer
' Demonstrates the production end of the producer and consumer pattern.
Private Shared Sub Produce(ByVal target As ITargetBlock(Of Byte()))
' Create a Random object to generate random data.
Dim rand As New Random()
' In a loop, fill a buffer with random data and
' post the buffer to the target block.
For i As Integer = 0 To 99
' Create an array to hold random byte data.
Dim buffer(1023) As Byte
' Fill the buffer with random bytes.
rand.NextBytes(buffer)
' Post the result to the message block.
target.Post(buffer)
Next i
' Set the target to the completed state to signal to the consumer
' that no more data will be available.
target.Complete()
End Sub
' Demonstrates the consumption end of the producer and consumer pattern.
Private Shared async Function ConsumeAsync(ByVal source As ISourceBlock(Of Byte())) As Task(Of Integer)
' Initialize a counter to track the number of bytes that are processed.
Dim bytesProcessed As Integer = 0
' Read from the source buffer until the source buffer has no
' available output data.
Do While await source.OutputAvailableAsync()
Dim data() As Byte = source.Receive()
' Increment the count of bytes received.
bytesProcessed += data.Length
Loop
Return bytesProcessed
End Function
Shared Sub Main(ByVal args() As String)
' Create a BufferBlock<byte[]> object. This object serves as the
' target block for the producer and the source block for the consumer.
Dim buffer = New BufferBlock(Of Byte())()
' Start the consumer. The Consume method runs asynchronously.
Dim consumer = ConsumeAsync(buffer)
' Post source data to the dataflow block.
Produce(buffer)
' Wait for the consumer to process all data.
consumer.Wait()
' Print the count of bytes processed to the console.
Console.WriteLine("Processed {0} bytes.", consumer.Result)
End Sub
End Class
' Output:
'Processed 102400 bytes.
'
In the ConsumeAsync method the following: source.OutputAvailableAsync() gets the error "OutputAvailableAsync' is not a member of 'System.Threading.Tasks.Dataflow.ISourceBlock(Of Byte())"
Thanks.
-
Apr 26th, 2013, 09:23 PM
#5
Re: TPL Data Flow: MSDN example not compiling
As a test, can you call it as a conventional method rather than an extension, i.e.
Code:
DataflowBlock.OutputAvailableAsync(source)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|