dotConnect for Zoho Desk Documentation
Devart.Common Namespace / DbCommandBase Class / BeginExecuteReader Method / BeginExecuteReader(AsyncCallback,Object) Method
The delegate to call when the asynchronous invoke is complete. If callback is a null reference (Nothing in Visual Basic), the delegate is not called.
State information that is passed on to the delegate.
Example

In This Topic
    BeginExecuteReader(AsyncCallback,Object) Method
    In This Topic
    Starts an asynchronous invocation of an System.Data.Common.DbCommand.ExecuteReader method with information for callback function.
    Syntax
    'Declaration
     
    Public Overloads Function BeginExecuteReader( _
       ByVal callback As AsyncCallback, _
       ByVal stateObject As Object _
    ) As IAsyncResult
    public IAsyncResult BeginExecuteReader( 
       AsyncCallback callback,
       object stateObject
    )

    Parameters

    callback
    The delegate to call when the asynchronous invoke is complete. If callback is a null reference (Nothing in Visual Basic), the delegate is not called.
    stateObject
    State information that is passed on to the delegate.

    Return Value

    An System.IAsyncResult interface that represents the asynchronous operation started by calling this method.
    Remarks

    BeginExecuteReader method enables you to execute a query on a server without having current thread blocked. In other words, your program can continue execution while the query runs on Zoho Desk so you do not have to wait for it.

    Refer to "Asynchronous Query Execution" article for detailed information.

    To start running a query, you have to call BeginExecuteReader method, which in turn invokes appropriate actions in another thread. Return value of this method must be assigned to an System.IAsyncResult object. After executing this method, the program flow continues.

    When you are ready to accept query results, call EndExecuteReader. If at the moment you call this function the query execution has not yet been finished, application stops and waits till the function returns. Then you can treat a DbDataReaderBase in a common way.

    Example
    In the example below the easiest way of executing an asynchronous operation is shown. First, all components are set up and a connection is opened. Second, a data retrieval operation is started. The operation state (done or in progress) is checked and a report is written to the console. At last query results are sent to DbDataReaderBase and rendered to the console.
    public void Async_Exec(DbConnectionBase myConnection)
    {
      DbCommandBase myCommand = (DbCommandBase)myConnection.CreateCommand();
      myCommand.CommandText = "SELECT AccountID, \"Account Name\", Phone FROM Accounts";
      Console.WriteLine("Starting asynchronous retrieval of data...");
      myConnection.Open();
      IAsyncResult cres = myCommand.BeginExecuteReader(null, null);
      if (cres.IsCompleted)
        Console.WriteLine("Completed.");
      else
        Console.WriteLine("Have to wait for operation to complete...");
      DbDataReader myReader = myCommand.EndExecuteReader(cres);
      try
      {
        while (myReader.Read())
        {
          Console.WriteLine(myReader.GetString(0) + " " + myReader.GetString(1) + " " + myReader.GetString(2));
        }
      }
      finally
      {
        myReader.Close();
        myConnection.Close();
      }
    }
    Public Sub Async_Exec(ByVal myConnection As DbConnectionBase)
      Dim myCommand As DbCommandBase = myConnection.CreateCommand()
      myCommand.CommandText = "SELECT AccountID, \"Account Name\", Phone FROM Accounts"
      Console.WriteLine("Starting asynchronous retrieval of data...")
      myConnection.Open()
      Dim cres As IAsyncResult = myCommand.BeginExecuteReader(Nothing, Nothing)
      If cres.IsCompleted Then
        Console.WriteLine("Completed.")
      Else
        Console.WriteLine("Have to wait for operation to complete...")
      End If
      Dim myReader As DbDataReader = myCommand.EndExecuteReader(cres)
      Try
        While myReader.Read()
          Console.WriteLine(String.Concat(myReader.GetString(0), " ", myReader.GetString(1), " ", myReader.GetString(2)))
        End While
      Finally
        myReader.Close()
        myConnection.Close()
      End Try
    End Sub
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also