Asynchronous Execution

Asynchronous execution allows you to execute commands in the background of the client or server, while allowing the application to continue executing other commands. Asynchronous execution is vital when dealing with large data sources over a large network.

In most cases, users will not wait more than a few seconds -- let alone two or three minutes -- for a response from your application indicating that a command is finally done. For instance, suppose an administrator of a large company determines to increase the prices of all items by one dollar. Suppose that this company has 10,000 products. When the user presses a button confirming the price change, she shouldn’t have to wait for all products to be updated before she can continue her work. Instead, once she confirms the price change, the application should issue an asynchronous command to the server to execute the update.

Executing a Command Asynchronously

Before you learn how to execute commands asynchronously, first take a look at a piece of code that takes a significant amount of time to execute:

com.ActiveConnection = "driver={SQL Server}; " _ & "server=JROFF_LAPTOP; " _ & "uid=sa; " _ & "database=Northwind" com.CommandText = "DELETE [Order Details (Backup)]; " sSQL = "INSERT INTO [Order Details (Backup)] " _ & " (OrderID, ProductID, UnitPrice, Quantity, Discount) " _ & "SELECT OrderID, ProductID, UnitPrice, Quantity, Discount " _ & "FROM [Order Details]; " com.CommandText = com.CommandText + sSQL Debug.Print ...

Get ADO: ActiveX Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.