I am converting some of the APIMASH projects from c# to vb.net and having to translate between the two.
You can find the APIMASH projects at: https://github.com/apimash/StarterKits
This is part of inheriting behavior of the System.Net.WebClient, for Windows Phone 8.
The c# code looks like this:
DownloadStringCompleted += (s, e) =>
{
if (e.Error == null)
{
tcs.TrySetResult(e.Result);
}
else
{
tcs.TrySetException(e.Error);
}
};
I tried two c# to vb.net conversion tools, DevFusion: http://www.developerfusion.com/tools/convert/csharp-to-vb/ and Telerik thttp://converter.telerik.com/.
Simple code converts fine but this example that does not, both do the same thing, could be the same engine:
DownloadStringCompleted += Function(s, e)
If e.[Error] Is Nothing Then
tcs.TrySetResult(e.Result)
Else
tcs.TrySetException(e.[Error])
End If
End Function
The lambda function works ok but that is not how event handlers are written in vb.net, this works much better:
AddHandler DownloadStringCompleted, Function(s, e)
If e.[Error] Is Nothing Then
tcs.TrySetResult(e.Result)
Else
tcs.TrySetException(e.[Error])
End If
End Function