Background Threads

Background thread support allows you to put long-running methods on a background thread so that your application can continue rather than wait for a method to finish. You can set certain methods in the Data Access classes and generated classes to run in asynchronous mode, that is, on a background thread. Most methods that can be blocked by the database or that could take a long time to finish can be set as asynchronous, including user-defined methods.

Note: Background thread support is for applications with graphical user interfaces, and will not work for command-line applications.

You always have the option of running all methods synchronously; the methods will run one after another in the order called. The next method does not start until the current one is finished. A method is complete when control returns to the application. Methods are set to run in synchronous mode by default.

If you use asynchronous methods, a method is not necessarily complete when control returns to the program, but rather when the background thread reports a method complete event.

Exceptions can be thrown by the foreground thread, before the method is placed on a background thread; this completes the method. Also, they can be thrown by the background thread, in which case the thread will report an exception event, and will complete the method.

Data Access Builder generates code that supports background threads. By default, this is turned off. However, Data Access classes allow you to set and test background thread with the following methods:

To run an object's methods on the background thread, use code similar to the following example:

Employee theEmployee;
theEmployee.setAsynchronous(true);
theEmployee.add();  // the add method will run on a background thread;


User-Defined Methods


Data Access Class Library and Generated Class Reference