Created
September 25, 2012 15:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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