Preemptive multitasking in the Win32 API makes it easy to implement asynchronous query processing. Use one of the following ways to implement asynchronous query processing, depending on whether you want your application to exhibit asynchronous behavior between processes or within a single process.
Although dbsqlexec is synchronous from the calling thread's perspective (dbsqlexec returns only when SQL Server processes the query and is ready to return results), the preemptive nature of the Win32 API allows other applications or threads of the same application to continue to work and process user input while the query is executing.
Use threads. The easiest way to implement asynchronous processing within a process is to use Win32 threads. You can spawn a thread that calls dbsqlexec and continue to do other work or continue to receive user input while the query is being processed.
Single-thread approach. If you require a single-thread process to implement asynchronous query processing, use the asynchronous DB-Library functions dbsqlsend, dbdataready, and dbsqlok in combination with the PostMessage function, as shown in this example:
case WM_SENDQUERY: dbsqlsend(dbproc); PostMessage(hWnd,WM_CHECKQUERY,0,0L); break; case WM_CHECKQUERY: if (dbdataready(dbproc)) { dbsqlok(dbproc); PostMessage(hWnd,WM_GETRESULTS,0,0L); } else { PostMessage(hWnd,WM_CHECKQUERY,0,0L); } break;