Skip to content

Instantly share code, notes, and snippets.

@ielcoro
Created September 25, 2012 15:18
Show Gist options
  • Save ielcoro/3782548 to your computer and use it in GitHub Desktop.
Save ielcoro/3782548 to your computer and use it in GitHub Desktop.
Implementación del patrón APM en un WebService clásico usando Task
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service2
Inherits System.Web.Services.WebService
<WebMethod>
Public Function BeginHelloWorld(ByVal callback As AsyncCallback, ByVal state As Object) As IAsyncResult
Dim tarea As Task(Of Boolean) = Task(Of Boolean).Factory.StartNew(Function() HelloWorld(), state)
If Not callback Is Nothing Then
tarea.ContinueWith(Sub(t) callback(tarea))
End If
Return tarea
End Function
Private Function HelloWorld() As Boolean
Threading.Thread.Sleep(5000)
Return True
End Function
<WebMethod>
Public Function EndHelloWorld(ByVal result As IAsyncResult) As Boolean
Return CType(result, Task(Of Boolean)).Result
End Function
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment