Export (0) Print
Expand All
Expand Minimize

EndEventHandler Delegate

Represents the method that handles asynchronous events such as application events.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)

'Declaration
Public Delegate Sub EndEventHandler ( _
	ar As IAsyncResult _
)

Parameters

ar
Type: System.IAsyncResult

The IAsyncResult that is the result of the BeginEventHandler operation.

This delegate is called by the event source when completion of the asynchronous operation is signaled by a callback to the BeginEventHandler delegate.

When you create an EndEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see Events and Delegates.

The following code example uses the EndEventHandler delegate to register a handler for an asynchronous page.

<%@ page language="VB" Async="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  Dim myRequest As System.Net.WebRequest

  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Label1.Text = "Page_Load: Thread #" & System.Threading.Thread.CurrentThread.GetHashCode()

    Dim bh As New BeginEventHandler(AddressOf Me.BeginGetAsyncData)
    Dim eh As New EndEventHandler(AddressOf Me.EndGetAsyncData)

    Me.AddOnPreRenderCompleteAsync(bh, eh)

    ' Initialize the WebRequest object.
    Dim address As String
    address = "http://localhost/"
    myRequest = System.Net.WebRequest.Create(address)

  End Sub

  Function BeginGetAsyncData(ByVal src As Object, ByVal args As EventArgs, ByVal cb As AsyncCallback, ByVal state As Object) As IAsyncResult
    Label2.Text = "BeginGetAsyncData: Thread #" & System.Threading.Thread.CurrentThread.GetHashCode()
    Return Me.myRequest.BeginGetResponse(cb, state)
  End Function

  Sub EndGetAsyncData(ByVal ar As IAsyncResult)
    Label3.Text = "EndGetAsyncData: Thread #" & System.Threading.Thread.CurrentThread.GetHashCode()

    Dim myResponse As System.Net.WebResponse
    myResponse = Me.myRequest.EndGetResponse(ar)

    Dim reader As New System.IO.StreamReader(myResponse.GetResponseStream())
    result.Text = reader.ReadToEnd()
    myResponse.Close()
  End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>
      Page.AddOnPreRenderCompleteAsync Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:label id="Label1" runat="server">
        Label 1</asp:label><br />
      <asp:label id="Label2" runat="server">
        Label 2</asp:label><br />
      <asp:label id="Label3" runat="server">
        Label 3</asp:label><br />
      <asp:textbox id="result" runat="server" textMode="multiLine" ReadOnly="true" columns="80" rows="25" />
    </form>
  </body>
</html>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft