title: Delegate function to return value
body: <p>I am trying to get value from the delegate function. Basically I am trying to get the richboxtext line length from delegate function.</p>
  
  <p>Here is my function</p>
  
  <pre><code>Private Delegate Function getrichlengthmain(ByVal TB As RichTextBox) As String
  
  Private Function getrichlenghtdele(ByVal TB As RichTextBox) As string
  
          Return TB.Lines.Length
  
  
  End Function
  </code></pre>
  
  <p>And I am calling it by  </p>
  
  <pre><code>Dim d As getrichlengthmain
  
          d = AddressOf getrichlenghtdele
  
  dim returnvalue as string
  
  returnvalue = d.BeginInvoke(FstList,nothing,nothing)
  </code></pre>
  
  <p>2 problems in this code</p>
  
  <p>1st problem</p>
  
  <p>when I change the code from "returnvalue = d.BeginInvoke(FstList,nothing,nothing)" to "d.BeginInvoke(FstList,nothing,nothing)"</p>
  
  <p>The cross-thread error popout while debuiging</p>
  
  <p>2nd problem</p>
  
  <p>How do I get the value from the function without getting any cross thread error.</p>
  
  <p>Very thanks for your time and thanks in advance for solving it. </p>