vb.net task.delay locks browser

I am trying to do a very simple job in vb.net 4.5 framework; Create and run a simple Async Task that will symbolize (making several database calls asynchrnously/ parallel).

I am using vs2012 and vb.net Very simple MVC app and one control.

The code is simple>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim newTask As Task(Of String) = TryPause()
    lblResults2.Text = newTask.Result
End Sub

Public Async Function TryPause() As Task(Of String)
    Await Task.Delay(100)
    Return "hello World"
End Function

Code runs fine when the "task.delay" is remarked out. But if it stays inside of the code, the Browser locks up.

Notice: thread.sleep works fine....

What am i missing?

Upvotes: 0

Views: 2345

Answers (1)

Stephen Cleary
Stephen Cleary

Reputation: 456707

As @SLaks correctly pointed out, the Result is causing a deadlock. I explain this in more detail on my blog and in a recent MSDN article.

Upvotes: 2

Related Questions