class TMtxProgressDialog : public TMtxComponent;
Manages and provides progress indicators of multi-threaded algorithms.
The TMtxProgressDialog component greatly simplifies the display of progress indicators and offers built-in support to cancel the execution of algorithms running in it's background thread. The progress can be indicated with events or by displaying its improvised progress dialog.
The design does not use the Synchronize procedure to update progress indicators and makes the most out of the available CPU power.
Usage example:
myProgress.DefineLoop(0, 1000-1); //how many times OnCompute should be called myProgress.OnCompute := MyCompute; //Mycompute will be called from a single background thread myProgress.OnProgressUpdate := MyProgressUpdate; //for progress indicators. Runs in main apps thread myProgress.Start;
When the processing finishes, the OnProgressUpdate will be called with TMtxProgressEvent.peCleanUp param from the main UI thread. The computation can be cancelled, by setting
myProgress.Cancel := True;
If the desire is to cancel and to block execution until all the processing has stopped call:
myProgress.Stop;
If the desire is to block execution and wait until all the processing has stopped call:
myProgress.WaitToFinish; // prefer OnProgressUpdate to detect the end (!)
The blocking calls however defeat the primary purpose of this component, which is to provide non-blocking interface to launch, track and detect the end of processing.
The component is targeted at user interaction with the UI and its one internal thread should not be used for massivally parallel computations. Use MtxVec.DoForLoop for such tasks. DoForLoop could/should/can be placed inside of MyCompute to do the actual mult-threaded computation.
Constructors
| Name | Description |
|---|---|
| TMtxProgressDialog |
Destructors
| Name | Description |
|---|---|
| ~TMtxProgressDialog |
Properties
| Name | Type | Description |
|---|---|---|
| BlockAssign | bool | Block streaming of specific properties when storing only a "template". |
| Cancel | bool | Allows execution stop by user. |
| Counter | int | Counts number of loops. |
| DialogCaption | System::UnicodeString | Custom caption for the built-in progress dialog form. |
| EditorActive | bool | Returns True, if the component editor is displayed. |
| InfiniteLoop | bool | Call TMtxProgressDialog::OnCompute in infinite loop. |
| InternalLoop | bool | Number of TMtxProgressDialog::OnCompute calls. |
| Loops | int | Number of loops to execute if TMtxProgressDialog::InternalLoop property is set to True. |
| Max | int | Sets the upper index of "for loop". |
| Min | int | Deines the lower index of the "for loop". |
| Name | DewString | |
| OnBeforeDestroy | ::Dew::tNotifyEvent | Event executed just before the object will be destroyed. |
| OnCleanUp | ::Dew::tNotifyEvent | Event used to perform clean up for the thread. |
| OnCompute | TComputeEvent | Place the actual threading algorithm in this event. |
| OnException | TExceptionEvent | Triggered when an exception has occured inside the Thread and the thread is about to exit. |
| OnInitialize | ::Dew::tNotifyEvent | Event used to perform initialization for the thread. |
| OnProgress | ::Dew::tNotifyEvent | Event used for progress indicators. |
| OnProgressUpdate | TProgressUpdateEvent | Called before the thread start executing. |
| Reference | TReferenceList* | Stores a list of components that have to be notified, when this component is destroyed. |
| Runtime | TMtxProgressRuntime* | Holds internal runtime object. |
| ShowDialog | bool | If True, the component will display it's default progress dialog. |
| TerminatingException | System::UnicodeString | Returns string different from nil, if an exception was raised during processing. |
| ThreadBypass | bool | Bypass thread. |
| ThreadName | System::UnicodeString | Allows the user to specify the name of the thread. |
| ThreadPriority | ::Dew::tThreadPriority | Thread priority. |
| UpdateInterval | int | Defines the time interval. |
Methods
| Name | Description |
|---|---|
| AllowStreaming | Returns the negatated value of BlockAssign. |
| Assign | Assign values of all published properties from Source. |
| AssignTemplate | Assign values of "template-like" published properties from Source. |
| Bridge_CleanUp | |
| Bridge_Compute | |
| Bridge_Exception | |
| Bridge_Initialize | |
| Bridge_ProgressTick | |
| Bridge_ProgressUpdate | |
| CancelClick | |
| CreateProgressUI | |
| DefineLoop | Set the range of loop with one procedure call. |
| DefineProgressBar | Control external progress bar. |
| DoThreadCleanUp | |
| DoThreadInit | |
| EditorClass | To be overriden in descendanr classses. |
| GetDialogCaption | |
| GetOnBeforeDestroy | |
| GetRuntime | |
| GetShowDialog | |
| GetTerminatingException | |
| LoadFromStream | Load the component from Src stream. |
| LoadTemplateFromFile | Load a template from file. |
| LoadTemplateFromStream | Load a template from stream. |
| ProgressTick | |
| ReferenceRemoved | |
| Reset | Reset is called after loading the data from stream or file. |
| SaveTemplateToFile | Save template to file. |
| SaveTemplateToStream | Save template to stream. |
| SaveToStream | Save the component to Dst stream. |
| Start | Call Start to start the execution of the thread. |
| Stop | Call Stop to request the loop to stop executing. |
| Terminate | Signals the thread that it should terminate. |
| WaitToFinish | Returns when the thread has finished. |
Fields
| Name | Type | Description |
|---|---|---|
| AForm | TForm * | Points to the progress dialog form, showing while thread is running, if ShowDialog property is True. |
| CancelButton | TButton * | |
| Panel | TPanel * | |
| ProgressBar | TProgressBar * | |
| Tag | intptr_t | |
| WndList | void * |