Results 1 to 5 of 5

Thread: [RESOLVED] TPL Data Flow: MSDN example not compiling

  1. #1

    Thread Starter
    Hyperactive Member nickwrs's Avatar
    Join Date
    Jan 2000
    Location
    Atlanta, Ga
    Posts
    398

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: TPL Data Flow: MSDN example not compiling

    Quote Originally Posted by nickwrs View Post
    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

  4. #4

    Thread Starter
    Hyperactive Member nickwrs's Avatar
    Join Date
    Jan 2000
    Location
    Atlanta, Ga
    Posts
    398

    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.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width