Convert async Task from c to vb net

0 votes

I'm using a C# to VB.NET converter to attempt and convert this code, however there are several errors.

private async Task OnRequestBlockResourceEventHandler(object sender, SessionEventArgs e)
            => await Task.Run(
                () =>
                {
                    if (e.HttpClient.Request.RequestUri.ToString().Contains("analytics"))
                    {
                        string customBody = string.Empty;
                        e.Ok(Encoding.UTF8.GetBytes(customBody));
                    }
                });

and the VB.NET code conversion is here:

Private Async Function OnRequestBlockResourceEventHandler(ByVal sender As Object, ByVal e As SessionEventArgs) As Task
    Return Await Task.Run(Function()

                              If e.HttpClient.Request.RequestUri.ToString().Contains("analytics") Then
                                  Dim customBody As String = String.Empty
                                  e.Ok(Encoding.UTF8.GetBytes(customBody))
                              End If
                          End Function)
End Function

The error shows this

Comma, ')', or a valid expression continuation expected.

'Return' statements in this Async method cannot return a value since
the return type of the function is 'Task'. Consider changing the
function's return type to 'Task(Of T)'
Dec 12, 2022 in C# by Roshan
• 300 points

edited 1 day ago 81 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP