Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Unfortunately, the version of VB used with Visual Studio 2008 will require you to break this into three methods (the original, plus one for each of the lambda expressions), because the older version of VB.Net did not yet support multi-line lambda expressions. We have to adapt things so we can fit the lambda expressions into a single line to close over the captured variables properly. If you were to use the same version of Visual Studio, VB.Net would be able to do it in the same way as C# (at least in this case), because the version of VB.Net included with Visual Studio 2010 does support multi-line lambda expressions.</p> <p>I think this will do it, but check it: I typed all this right into the reply window and it's complicated enough I likely have a mistake or two. </p> <pre class="lang-vb prettyprint-override"><code>Public Sub sendAndBlock(ByVal msgs As List(Of ISendable)) Dim taskCount As Integer = msgs.Count Dim fini As New AutoResetEvent(False) 'vb.net for vs2008 is limited to single-line lambdas. ' But we still need to create a closure to capture the fini and taskCount variables ' Means we can't translate old code line-for-line ' Solution is to abstract the old lambda expressions out to their own methds that we can call in a single line msgs.ForEach(Function(m) QueueMessage(m, fini, taskCount)) fini.WaitOne() End Sub Private Sub QueueMessage(ByVal msg As ISendable, ByVal signaler As AutoRestEvent, ByRef taskCount As Integer) ThreadPool.QueueUserWorkItem(Function(n) SendQueuedMessage(msg, taskCount, signaler), msg); End Sub Private Sub SendQueuedMessage(ByVal msg As ISendable, ByRef TaskCount As Integer, ByVal signaler As AutoResetEvent) Me.send(msg) 'Not sure about this line, because `Set` is a reserved word in VB If Interlocked.Decrement(taskCount) = 0 Then signaler.Set() End Sub </code></pre> <p>I might be able to get this down to two methods instead of three, because one of the extra methods condensed down to a single line, but for the sake of simplicity and readability I'll leave it here. </p> <p>Finally, if it's enough to just be able to target .Net 3.5 from Visual Studio 2010, you can get by with something closer to the original, because you can use the newer VB language syntax features from Visual Studio 2010 with .Net 3.5.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload