Generic Handler : Async ASHX File
Imports System.Web
Imports System.Data.SqlClient
Imports System.Threading.Tasks
Public Class AsyncHandler
Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = “text/plain”
Task.Run(Async Sub()
Await AddToLogAsync(context)
Await ReadQueryStringAsync(context)
Await ReadPostFormVariablesAsync(context)
Await CallDatabaseResultAsync(context)
End Sub).GetAwaiter().GetResult()
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Private Async Function AddToLogAsync(ByVal context As HttpContext) As Task
‘ Add to log
Await Task.Delay(100)
End Function
Private Async Function ReadQueryStringAsync(ByVal context As HttpContext) As Task
‘ Read query string variables
Await Task.Delay(100)
End Function
Private Async Function ReadPostFormVariablesAsync(ByVal context As HttpContext) As Task
‘ Read post form variables
Await Task.Delay(100)
End Function
Private Async Function CallDatabaseResultAsync(ByVal context As HttpContext) As Task
‘ Call database and get result
Await Task.Delay(100)
End Function
End Class